2017-07-16 39 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

相關問題