2011-01-14 18 views
5

W jaki sposób mogę uzyskać mój skrypt .jsx po zakończeniu wykonywania innego skryptu .jsx?Skrypt .jsx Adobe InDesign wykonuje skrypt .jsx

Może to pomoże zrozumieć, co próbuję zrobić:

// WebCard.jsx file 

function mySnippet(){ 
    //<fragment> 
    var myPageName, myFilePath, myFile; 
    var myDocument = app.documents.item(0); 
    var myBaseName = myDocument.name; 
    for(var myCounter = 0; myCounter < myDocument.pages.length; myCounter++){ 
     myPageName = myDocument.pages.item(myCounter).name; 
     app.jpegExportPreferences.jpegExportRange = ExportRangeOrAllPages.exportRange; 
     app.jpegExportPreferences.resolution = 96; 
     app.jpegExportPreferences.pageString = myPageName; 

      switch(myPageName) { 
     case "1" : myPageName = "EN FRONT WebCard"; 
      docType = "Web/Web Cards" break; 
     case "2" : myPageName = "EN BACK WebCard"; 
      docType = "Web/Web Cards" break; 
     case "3" : myPageName = "ES FRONT WebCard"; 
      docType = "Web/Web Cards" break; 
     case "4" : myPageName = "ES BACK WebCard"; 
      docType = "Web/Web Cards" break; 

    } 
     fileName = group + " " + myPageName + " " + date + ".jpg"; 

     myFilePath = dirPath + docType + "/" + fileName; 
     myDocument.exportFile(ExportFormat.jpg, File(myFilePath), false); 
    } 
    //</fragment> 
} 
//</snippet> 
       // execute PrintCard.jsx file 


//<teardown> 
function myTeardown(){ 
} 
//</teardown> 

nadzieję, że pomoże?

Odpowiedz

3

Oto fragment jakiegoś ExtendScriptu używam do uruchamiania innych skryptów; Używałem go w programie After Effects, ale prawdopodobnie działa w programie InDesign, zbyt:

var theScriptFile = new File("/path/to/file.jsx"); 

var oldCurrentFolder = Folder.current; 
Folder.current = theScriptFile.parent; 

theScriptFile.open(); 
var theScriptContents = theScriptFile.read(); 
theScriptFile.close(); 

gCurrentScriptFile = theScriptFile; 

if(doDebug) 
    debugger; 

// You have entered the debugger in Launcher... 
// to debug the script you've launched, step 
// into the eval() function below. 
// 
eval("{" + theScriptContents + "}"); 

Folder.current = oldCurrentFolder; 
gCurrentScriptFile = ""; 

Podejście to odczytać plik i eval go. (PS kolejny dobry tag byłby ExtendScript, tutaj). Patrz również: http://omino.com/pixelblog/2007/11/15/binary-files-in-extendscript/

+0

Mam problem z przeczytaniem tego, gdzie powinienem umieścić skrypt, który chciałbym uruchomić (PrintCard.jsx)? – jmituzas

+0

var theScriptFile = new File ("/ absolute/path/to/PrintCard.jsx"); ale ... możesz potrzebować absolutnej ścieżki ... aplikacje adobe mogą zachowywać się inaczej w relatywnych ścieżkach; będziesz musiał poeksperymentować z InDesign, aby zobaczyć, czy możesz zrobić nowy plik ("../ PrintCard.jsx") lub podobny; jeśli to możliwe, staraj się unikać absolutnej ścieżki, którą myślę. –

+0

Hahaha Powinienem przeczytać to od nowa, ponieważ napisałeś: new File ("/ path/to/file.jsx"); - przepraszam za to ... – jmituzas

5

Można łatwo to inny skrypt, który zostanie wykonany w miejscu, gdzie je umieścić:

// ... Do something (will be executed before teardown script) 


#include "../path/to/teardown/script.jsx" 
// the path can be absolute or relative. 

to powinno działać w programie InDesign od CS3 w górę.

+0

Działa dla mnie idealnie! Dziękuję Ci! – Syjin