【问题标题】:Vanishing panel消失板
【发布时间】:2014-04-03 04:16:23
【问题描述】:

我创建了一个 jsx 脚本,该脚本在 illustrator 中创建了一个自定义对话框,允许我将文本文件加载到字符串中。在 Extendscript 中似乎一切正常,但是当我保存它并独立运行它时Illustrator 对话框出现然后立即消失。任何想法,我都删除了所有$writeIn 声明。

我环顾四周,但似乎什么都没有 代码如下:

function init() {
dataFile=""//Load in paths to users day file and folder where spreadsheets are stored
var readFile = File(appPath+ "pathData"+".txt");
     if(readFile != null) {
         readFile.open('r')
         dataPath=readFile.read();
         readFile.close();
         dataPath=dataPath.replace(/[\n\r]/g, '');//Seems to need this as without there is a cariage return added to the end of the string somewhere in the saving of the file

         };
     else dataPath="Press button to set path to day folder";
    readFile = File(appPath+ "pathDay"+".txt");
    if(readFile != null) {
         readFile.open('r')
         dayPath=readFile.read();
         readFile.close()
         dayPath=dayPath.replace(/[\n\r]/g, '');//Seems to need this as without there is a cariage return added to the end of the string somewhere in the saving of the file
         //$.writeln("dayPath=",dayPath);
         };
     else dayPath="Press button to set path to day folder";

    var initPanel=new Window("palette","iPlot", undefined);
    initPanel.orientation="column"
    var group1=initPanel.add("group",undefined,"GroupOne");
    group1.orientation="column"
    var loadButton=group1.add("button",undefined,"Load data");
    loadButton.onClick = function() {
        initPanel.close();
        loadFile();
    };
    var closeButton=group1.add("button",undefined,"Close");
     closeButton.onClick = function() {
        //$.writeln("Close button pressed");
        initPanel.close();
    };
    var setipButton=group1.add("button",undefined,"Setup");
     setipButton.onClick = function() {
         setup()
    };
    initPanel.center();
    initPanel.show();
    return true;
    }

【问题讨论】:

    标签: javascript adobe-illustrator extendscript


    【解决方案1】:

    只要您的脚本运行,调色板和对话框才会“活动”。据我所知(几乎没有),一旦你的脚本“结束”,即你想在 Illustrator 的面板之外工作,Extendscript 引擎就会认为脚本本身已经结束。

    解决此问题的常用方法是将私有资源 专用于您的脚本。您可以通过创建一个专用的“引擎”来做到这一点,该“引擎”将保留在内存中。以下两行添加到最顶部时可以解决问题:

    #target Illustrator
    #targetengine main
    

    如果您从 Illustrator 中运行脚本,则第一个已过时,但如果您从其他地方(例如从 Extendscript Toolkit 编辑器中)运行它,则需要它。第二个设置一个指定名称的私有引擎;在本例中为 main,但如果您同时运行多个调色板,则每个调色板都需要唯一的名称。

    参见http://forums.adobe.com/thread/1238745——尤其是最后一篇帖子。

    【讨论】:

    • 谢谢这真的很有用和帮助。我发现如果我用“new Window(”dialog”...”替换“new Window(“palette”...”的两个实例作为临时修复,但是当我想让脚本自动运行时,您的解决方案会有所帮助在启动时运行并在 illustrator 中创建一个浮动调色板。
    猜你喜欢
    • 2011-01-29
    • 2018-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多