Eh bien, j'ai découvert. Le plus dur a été de trouver une bonne documentation pour l'API de script javascript Indesign ... La documentation d'Adobe est soit difficile à trouver, soit manquante. En outre, ils publient tout en format PDF, ce qui est vraiment ennuyeux à mon humble avis. J'ai trouvé un good online documentation for CS6. Je travaille sur CC mais tout ce que j'ai utilisé semble le même. Quoi qu'il en soit, j'ai créé le script suivant, très incomplet et pas parfait, mais fonctionne pour moi ...
// 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();