2017-07-16 73 views
0

我很拼命地为我的问题寻找解决方案,我需要在InDesign中放置大量的内联图形,但对于某些原因是它不工作我对Javascript的知识非常贫乏,我的时间不多了,所以我不能花太多时间学习JS。我正在使用优胜美地在iMac上使用InDesign CC2014。f [i] .insertionPoints [0] .rectangles.add({geometricBounds:

以下错误消息弹出式:

错误扣:

error snap

如果有人给我一个提示,我会很高兴。

main(); 
 

 
function main() { 
 
var name, f, file, text, 
 
arr = []; 
 

 
if(app.documents.length != 0) { 
 
    var doc = app.activeDocument; 
 
    var folder = Folder.selectDialog("Choose a folder with images"); 
 

 
    if (folder != null) { 
 
     app.findObjectPreferences = app.changeGrepPreferences = NothingEnum.NOTHING; 
 
     app.findGrepPreferences.findWhat = "@[email protected]"; 
 
     f = doc.findGrep(true); 
 

 
     for (i = 0; i < f.length; i++) { 
 
      name = f[i].contents.replace(/@/g, ""); 
 
      file = new File(folder.fsName + "/" + name); 
 

 
      if (file.exists) { 
 
       f[i].contents = ""; 
 
       var rect = f[i].insertionPoints[0].rectangles.add({geometricBounds:[0,0, 60, 40.667 ]}); 
 
\t \t \t \t rect.place (file); 
 
\t \t \t \t rect.fit (FitOptions.FRAME_TO_CONTENT); 
 
       
 
      } 
 
      else { 
 
       arr.push("File doesn't exist '" + name + "'"); 
 
      } 
 
     } 
 

 
     app.findObjectPreferences = app.changeGrepPreferences = NothingEnum.NOTHING; 
 

 
     arr.push("------------------------------------------"); 
 
     text = arr.join("\r"); 
 
     writeToFile(text); 
 
    } 
 
} 
 
else{ 
 
    alert("Please open a document and try again."); 
 
} 
 
} 
 

 
function writeToFile(text) { 
 
var file = new File("~/Desktop/Place inline images.txt"); 
 
if (file.exists) { 
 
    file.open("e"); 
 
    file.seek(0, 2); 
 
} 
 
else { 
 
    file.open("w"); 
 
} 
 
file.write(text + "\r"); 
 
file.close(); 
 
}

回答

1

问题是 - 可能 - 原因脚本编辑找到的内容,并指的是在代码的下一行。 我建议使用后向循环并移动f [i] .contents =“”后面的行。

喜欢的东西:

main(); 

function main() { 
var name, f, cF, file, text, 
arr = []; 

if(app.documents.length != 0) { 
    var doc = app.activeDocument; 
    var folder = Folder.selectDialog("Choose a folder with images"); 

    if (folder != null) { 
     app.findObjectPreferences = app.changeGrepPreferences = NothingEnum.NOTHING; 
     app.findGrepPreferences.findWhat = "@[email protected]"; 
     f = doc.findGrep(true); 

     while(cF = f.pop()) { 
      name = cF.contents.replace(/@/g, ""); 
      file = new File(folder.fsName + "/" + name); 

      if (file.exists) { 
       var rect = cF.insertionPoints[0].rectangles.add({geometricBounds:[0,0, 60, 40.667 ]}); 
       rect.place (file); 
       rect.fit (FitOptions.FRAME_TO_CONTENT); 
       cF.contents = ""; 
      } 
      else { 
       arr.push("File doesn't exist '" + name + "'"); 
      } 
     } 

     app.findObjectPreferences = app.changeGrepPreferences = NothingEnum.NOTHING; 

     arr.push("------------------------------------------"); 
     text = arr.join("\r"); 
     writeToFile(text); 
    } 
} 
else{ 
    alert("Please open a document and try again."); 
} 
} 

function writeToFile(text) { 
var file = new File("~/Desktop/Place inline images.txt"); 
if (file.exists) { 
    file.open("e"); 
    file.seek(0, 2); 
} 
else { 
    file.open("w"); 
} 
file.write(text + "\r"); 
file.close(); 
} 
+0

或者使用try/catch子句。 –

+0

感谢您的回复。是的,这是问题,它不能代替已经被删除或清空的东西。它帮助了很多。 – alejorojas2k

相关问题