Indesign CS6脚本 - 导出图像 [英] Indesign CS6 Scripting - Exporting images
问题描述
我无法在indesign cs6中编写一个js脚本来导出我的格式化图像。下面的代码(在本网站上发现并稍作修改)仅打开文档。
I'm having trouble writing a js script in indesign cs6 to export my formatted images. the code below (found on this website and slightly modified) only opens the document.
理想情况下,脚本将循环遍历我的文档中的所有格式化/裁剪图像并导出他们进入桌面上的一个新文件夹,但使用原始文件名。
ideally the script would loop through all of the formatted/cropped images in my document and export them into a new folder on the desktop, but with the original file names.
任何帮助将不胜感激:
test();
function test(){
var myDoc = app.open('/Users/StudioA/Desktop/file.indd');
var myGroups = myDoc.groups;
//for each group...
for (var i = 0;i < myGroups.length; i++){
// for each rectangle in the group...
for(var r = 0; r< myGroups[i].rectangles.length; r++){
var myRect = myGroups[i].rectangles[r];
app.jpegExportPreferences.exportResolution = 300;
app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MAXIMUM;
//give it a unique name
var myFile = new File('/Users/StudioA/Desktop/Export/' + myRect.name + '.jpg');
myRect.exportFile(ExportFormat.JPG, myFile);
}
}
}
推荐答案
文件名不在矩形上,而是位于与放置图形相关的链接上。
这应该是你想要的一个开放的文件:
The file name isn't located on the rectangle but on the link related to the placed graphic. This should do what you want given an open document:
test();
function test(){
function test(){
var myDoc = app.activeDocument,
apis = myDoc.allPageItems, rect, fileName;
while ( rect = apis.pop() )
{
if ( !(rect instanceof Rectangle) || !rect.graphics[0].isValid ){ continue; }
fileName = File ( rect.graphics[0].itemLink.filePath ).name;
fileName = fileName.replace( /\.[a-z]{2,4}$/i, '.jpg' );
app.jpegExportPreferences.exportResolution = 300;
app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MAXIMUM;
//give it a unique name
var myFile = new File (Folder.desktop+"/"+ fileName);
rect.exportFile(ExportFormat.JPG, myFile);
}
}
这篇关于Indesign CS6脚本 - 导出图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!