2012-07-19 67 views
0



我使用的方法  myFile.execute()  以編程方式打開InDesign文檔(在這種情況下,它是一個空白文檔與施加到其上的樣式)。
InDesign CS5腳本:打開文檔沒有響應,並且不會引發錯誤?


文件有時被打開,而在其他時候,它是 ...看來,如果腳本沒有足夠的時間來打開文件時,它完成之前。


這發生在我身上,因爲在測試時用  alert(template.name)  它 顯示我正在尋找的文件名,並且腳本 拋出一個錯誤應用  File(template).execute()  (變量時  template  本身已經是  File  對象,但只是  template.execute()  也不能正常工作)。


下面是相關代碼:

function openStylesTemplate() 
{ 
    var templateFolder = getScriptFolder(); // with the function below 
    var fileArray = templateFolder.getFiles("*.indd"); // an array of all InDesign documents in this script's same folder 

    try 
    { 
     var template = fileArray[0]; // the ONLY InDesign document in the folder 
     File(template).execute(); // open the InDesign template document 
    } 
    catch(e) 
    { 
     alert("Error: " + e.message + "\n\n" + 
       "Make sure the InDesign styles document is in the same folder as this script,\n" + 
        "and that it is the ONLY InDesign document in this folder, and try again.\n\n" + 
       "This script is in this folder: " + templateFolder + "."); 

     exit(); 
    } 
} // end of function openStylesTemplate 


所以,可以在腳本可能沒有足夠的時間來加載文件?如果是這樣,我應該在調用這個函數之前創建一個計時器嗎?還是有更好的方式來以編程方式打開InDesign文檔?

回答

1

打開一個不重要的文件不是File.execute()的問題,它只是從os的角度打開一個文件,而不參考文件本身。通過調用app.open (file);來打開文件。

+0

好的,所以沒有錯誤,我只是使用了錯誤的方法!感謝您澄清這些方法之間的差異。 – 2012-07-20 19:10:02

相關問題