2012-07-19 68 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

相关问题