質問

I've created a jsx script that creates a custom dialog box in illustrator that allows me to load a text file into a string.. It all seems to work OK in Extendscript but the moment I save it and run it standalone from Illustrator the dialog box appears then instantly vanishes. Any ideas, I've removed all the $writeIn statements.

I've looked around but there seems to be nothing on this Code lookes like ths:

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;
    }
役に立ちましたか?

解決

Palettes and dialogs only "live" as long as your script runs. As I understand it (barely), as soon as your script 'ends', i.e., you want to work outside the panel in Illustrator, the Extendscript engine thinks the script itself has ended.

The common cure for this is to dedicate private resources to your script. You do so by creating a dedicated "engine", which will persist in memory. The following two lines do the trick when added at the very top:

#target Illustrator
#targetengine main

The first one is obsolete if you run your script from within Illustrator, but it is required if you run it from elsewhere (such as from within the Extendscript Toolkit Editor). The second sets up a private engine with a specified name; in this case main but if you run several palettes at the same time, you need unique names for each.

See http://forums.adobe.com/thread/1238745 -- in particular, the very last post.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top