嗯,我发现了。最难的部分真的是为 Indesign javascript 脚本 API 找到一个好的文档…… Adobe 的文档要么很难找到,要么缺乏。此外,他们将所有内容都发布为 PDF,恕我直言,这真的很烦人。我找到了一个很好的 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();