在InDesign中使用Javascript 使用技巧

安装脚本脚本的位置位于

Windows® XP: ~Documents and Settingsuser_nameApplication DataAdobe
InDesignVersion 6.0Scripts
Mac OS®: ~/Users/user_name/Library/Preferences/Adobe InDesign/Version 6.0/Scripts
一旦安装了你想要安装的脚本,即可到Window > Automation > Scripts 打开脚本面板
运行脚本
这个就相对简单的多,只要打开面板中的“脚本”标签然后选中实施对象,双击你的脚本即可。
发送参数
var myParameters = ["Hello from DoScript", "Your message here."];
var myJavaScript = "alert("First argument: " + arguments[0] + "\rSecond argument:" + arguments[1]);";
app.doScript(myJavaScript, ScriptLanguage.javascript, myParameters);
使用SESSION
#targetengine "session" //当设置为启用为SESSION时,你运行脚本中的对象,知道InDesign关闭时才消失。
#targetengine "adobe"   //你也可以自己创建一个公共引擎
创建一个文档
var myDocument = app.documents.add();
打开一个文档
var myDocument = app.open(File("/c/myTestDocument.indd"), false);
var myLayoutWindow = myDocument.windows.add();
保存文档
app.activeDocument.save();
app.activeDocument.save(new File("/c/myTestDocument.indd"));
关闭文档
app.activeDocument.close();
for(myCounter = app.documents.length; myCounter > 0; myCounter–){ //关闭所有文档
app.documents.item(myCounter-1).close(SaveOptions.no);
}
定义页尺寸和文档长度
var myDocument = app.documents.add();
with(myDocument.documentPreferences){
pageHeight = "800pt";
pageWidth = "600pt";
pageOrientation = PageOrientation.landscape;
pagesPerDocument = 16;
}
定义出血和标志条
myDocument = app.documents.add();
//The bleed and slug properties belong to the documentPreferences object.
with(myDocument.documentPreferences){
//Bleed
documentBleedBottomOffset = "3p";  //如果出血的边距是相同的可以这样设置documentBleedUniformSize = true; documentBleedTopOffset = "3p";
documentBleedTopOffset = "3p";
documentBleedInsideOrLeftOffset = "3p";
documentBleedOutsideOrRightOffset = "3p";
//Slug
slugBottomOffset = "18p";          //如果标记条的边距是相同的可以这样设置documentSlugUniformSize = true;slugTopOffset = "3p";
slugTopOffset = "3p";
slugInsideOrLeftOffset = "3p";
slugRightOrOutsideOffset = "3p";
}
定义出血和标志条的颜色
with(app.activeDocument.pasteboardPreferences){
//Any of InDesign’s guides can use the UIColors constants…
bleedGuideColor = UIColors.cuteTeal;
slugGuideColor = UIColors.charcoal;
//…or you can specify an array of RGB values (with values from 0 to 255)
//bleedGuideColor = [0, 198, 192];
//slugGuideColor = [192, 192, 192];
}

设置页边距和列数
myDocument = app.documents.add();
with (myDocument.pages.item(0).marginPreferences){
columnCount = 3;
//columnGutter can be a number or a measurement string.
columnGutter = "1p";
bottom = "6p"
//When document.documentPreferences.facingPages == true,
//"left" means inside; "right" means outside.
left = "6p"
right = "4p"
top = "4p"
}

设置引导线
var myDocument = app.documents.add();
var myPageWidth = myDocument.documentPreferences.pageWidth;
var myPageHeight = myDocument.documentPreferences.pageHeight;
with(myDocument.pages.item(0)){
//Place guides at the margins of the page.
guides.add(undefined, {orientation:HorizontalOrVertical.vertical, location:marginPreferences.left});//左侧竖线
HorizontalOrVertical.vertical 竖线
guides.add(undefined, {orientation:HorizontalOrVertical.vertical, location:(myPageWidth – marginPreferences.right)});//右侧竖线
guides.add(undefined, {orientation:HorizontalOrVertical.horizontal, location:marginPreferences.top});//顶端横线
guides.add(undefined, {orientation:HorizontalOrVertical.horizontal, location:(myPageHeight – marginPreferences.bottom)});//底端横线
guides.add(undefined, {orientation:HorizontalOrVertical.vertical, location:(myPageWidth/2)});//中竖线
guides.add(undefined, {orientation:HorizontalOrVertical.horizontal, location:(myPageHeight/2)});//中横线
}

设置引导线2
var myDocument = app.documents.add();
with (myDocument.spreads.item(0)){
createGuides(4, 4, "1p", "1p", UIColors.gray, true, true,myDocument.layers.item(0));
}

Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: