2017-05-31 58 views
0

我有一个脚本可以找到图像名称并将其替换为图像。InDesign脚本,导入时调整图像大小

这就是我的InDesign文件中的文本的样子。

@ blue_dress_xl.JPG @

蓝色礼服XL

Lorem存有...

的文本是在3列,每列中的宽度是40667毫米。 当我使用脚本将图像替换为@ blue_dress_xl.JPG @时,图像以100%显示。

我不是那么强大的JS,我尝试了一些不同的东西,但它不是真的有效。

有没有办法将图像宽度设置为“40,667毫米”时,它被导入?

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].remove(); 
       f[i].insertionPoints[0].place(file); 
      } 
      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

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].remove(); 
 
       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.CONTENT_TO_FRAME); 
 
      } 
 
      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

感谢您的输入,它与此错误消息出现寿 http://i.imgur.com/46RAPQB.png – LateChicken

+0

比较遗憾的是,一个错字问题。请参阅rect.place(文件)修改并再次运行该脚本。 – Loic

+0

对不起,花了这么长时间回复,真的很忙。 它接近工作,但它不符合图像的比例。 所以我试着用\t \t \t \t rect.fit(FitOptions.FILL_PROPORTIONALLY); 接近我想要的东西,但如果图像是宽的,它会在每一边都切断它。 有没有办法说图像应该有40,667毫米的最大/最小宽度,所以它只是在图像的大小后的高度变化? – LateChicken