有没有一种方法可以在样式(脚本?)中使用变量来共享具有某些变体的样式,如颜色?InDesign风格变量
例如:我正在编写一本书,有多章。每章都是InDesign文档。我想为本书中的所有文档使用通用样式,但它们的颜色会有所不同。所以,而不是有多个对象样式:RoundedBox红色,RoundedBox蓝色等,我只会有一个样式,RoundedBox,并只输入颜色变量的值在某处...
有没有一种方法可以在样式(脚本?)中使用变量来共享具有某些变体的样式,如颜色?InDesign风格变量
例如:我正在编写一本书,有多章。每章都是InDesign文档。我想为本书中的所有文档使用通用样式,但它们的颜色会有所不同。所以,而不是有多个对象样式:RoundedBox红色,RoundedBox蓝色等,我只会有一个样式,RoundedBox,并只输入颜色变量的值在某处...
你有一个理由,只检查矩形,椭圆形和多边形?如果没有,你可以使用pageItems。沟形状选择和切换,并使用:
shapes = myDoc.allPageItems;
for (var i=0; i<shapes.length; i++)
{
if (shapes[i].appliedObjectStyle.name === oldStyle.name)
{
shapes[i].applyObjectStyle(newStyle);
}
}
既然你有一个单独的文档的每个章节,你也可以只改变你的对象风格的定义:
oldStyle.fillColor = newSwatch;
,所以你不要不必循环实际的物体。没有测试,但它应该工作。
嗯,我发现了。最难的部分是为Indesign JavaScript脚本API找到一份很好的文档... Adobe的文档很难找到或缺乏。另外,他们将所有内容都发布为PDF,恕我直言,这真的很烦人。我发现了一个good online documentation for CS6。我正在研究CC,但我使用的一切似乎都一样。无论如何,我已经创建了下面的脚本,非常不完整和不完美,但对我的作品......
// Setup the dialog UI
var myDialog = app.dialogs.add({
name: "Style Variables",
canCancel: true
});
// I usually never use 'with', but this is how it is done
// in Adobe's documentation...
with(myDialog.dialogColumns.add()) {
staticTexts.add({staticLabel: "Main Color swatch name:"});
staticTexts.add({staticLabel: "Style to replace:"});
staticTexts.add({staticLabel: "Replace style with:"});
staticTexts.add({staticLabel: "Choose shape type to target:"});
}
with(myDialog.dialogColumns.add()){
var swatchField = textEditboxes.add({editContents:'', minWidth:180}),
oldStyleField = textEditboxes.add({editContents:'', minWidth:180}),
newStyleField = textEditboxes.add({editContents:'', minWidth:180}),
shapeTypeField = dropdowns.add({stringList:['Rectangles', 'Ovals', 'Polygons']}); // Defaults to rectangles
}
// Get the user input and do stuff with it
var myResult = myDialog.show();
if (myResult === true)
{
var docs = app.documents,
myDoc = docs[0],
allStyles = myDoc.objectStyles,
oldStyle = allStyles.itemByName(oldStyleField.editContents),
newStyle = allStyles.itemByName(newStyleField.editContents),
swatches = app.documents[0].swatches,
newSwatch = swatches.itemByName(swatchField.editContents),
shapes;
// Get the shape type we are targetting:
switch(shapeTypeField.selectedIndex)
{
case 0:
shapes = myDoc.rectanges;
break;
case 1:
shapes = myDoc.ovals;
break;
case 2:
shapes = myDoc.polygons;
break;
default:
shapes = myDoc.rectangles;
}
// Set the base style color to the user chosen swatch:
newStyle.fillColor = newSwatch;
for (var i=0; i<shapes.length; i++)
{
if (shapes[i].appliedObjectStyle.name === oldStyle.name)
{
shapes[i].applyObjectStyle(newStyle);
}
}
}
else
{
alert('Script cancelled, nothing was done.');
}
// Destroy dialog box
myDialog.destroy();