2011-01-14 31 views
5

Làm cách nào để có tập lệnh .jsx khi hoàn thành việc thực thi tập lệnh .jsx khác?Kịch bản Adobe InDesign .jsx thực thi .jsx script

Có lẽ điều này sẽ giúp hiểu những gì tôi đang cố gắng để làm:

// 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> 

Hy vọng rằng sẽ giúp?

Trả lời

3

Đây là một đoạn của một số ExtendScript mà tôi sử dụng để khởi chạy các tập lệnh khác; Tôi đã sử dụng nó trong After Effects, nhưng nó cũng có thể hoạt động trong InDesign:

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 = ""; 

Cách tiếp cận là đọc tệp và đánh giá nó. (PS khác tag tốt sẽ ExtendScript, ở đây.) Xem thêm: http://omino.com/pixelblog/2007/11/15/binary-files-in-extendscript/

+0

Tôi gặp một chút khó khăn khi đọc, tôi sẽ đặt kịch bản mà tôi muốn khởi chạy ở đâu (PrintCard.jsx)? – jmituzas

+0

var theScriptFile = new File ("/ absolute/path/to/PrintCard.jsx"); nhưng ... bạn có thể cần đường dẫn tuyệt đối ... các ứng dụng adobe có thể hoạt động khác nhau về các đường dẫn tương đối; bạn sẽ phải thử nghiệm với InDesign để xem bạn có thể làm File mới ("../ PrintCard.jsx") hay tương tự; nếu có thể, cố gắng tránh con đường tuyệt đối mà tôi nghĩ. –

+0

Hahaha Tôi nên đọc lại nó kể từ khi bạn nói: tệp mới ("/ path/to/file.jsx"); - xin lỗi về điều đó ... – jmituzas

5

Bạn có thể dễ dàng bao gồm một kịch bản mà sẽ được thực hiện tại điểm mà bạn đưa nó:

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


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

này nên làm việc trong InDesign từ CS3 trở lên.

+0

Làm việc cho tôi một cách hoàn hảo! Cảm ơn bạn! – Syjin

Các vấn đề liên quan