Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Ce JavaScript pour InDesign va trouver les texte ayant le style "Basic Paragraph" et les objets avec les styles "Basic Graphics Frame" et "Basic Text Frame" pour faire un "Break Link to Style"This InDesign Script will apply a Break Link to Style to all text that has «Basic Paragraph» style or objects with "Basic Graphics Frame" or "Basic Text Fr…
/*
Ce script va trouver les texte ayant le style "Paragraphe standard" et les objets avec les styles [Bloc graphique standard] et [Bloc de texte standard] pour faire rupture du lien entre le texte et son style
This InDesign Script will apply a Break Link to Style to all text that has «Basic Paragraph» style or objects with "Basic Graphics Frame" or "Basic Text Frame" in an InDesign Document
Thanks to cms_phill (http://forums.adobe.com/thread/856718)
par benCloutier.com (www.groupetma.com)
*/
nomDuScript = "Rupture des styles standard";
dateRev = "1.5 (2015.05.4)";
myID = "ben@bencloutier.com";
try{
myDocument = app.activeDocument;
}catch(e){
alert("Aucun document ouvert!\nUn document doit être ouvert. Le script va quitter.");
exit();
}
changes = 0;
myBasicParagraph = myDocument.paragraphStyles.item(1).name;
BreakParaStyle = app.menuActions.itemByID(8500);
myBasicGraphicFrame = myDocument.objectStyles.item(1).name;
myBasicTextFrame = myDocument.objectStyles.item(2).name;
BreakObjStyle = app.menuActions.itemByID(113166);
var myChangesList = [];
function breakText(){
for (i=0; i<myDocument.stories.length; i++){
for (j=0; j<myDocument.stories[i].paragraphs.length; j++){
// app.select(myDocument.stories[i].paragraphs[j]);
if(myDocument.stories[i].paragraphs[j].appliedParagraphStyle == myDocument.paragraphStyles.item(myBasicParagraph)){
myChangesList.push(myDocument.stories[i].paragraphs[j].contents);
//Break paragraph styles
app.select(myDocument.stories[i].paragraphs[j]);
try {
BreakParaStyle.invoke();
}
catch (err){};/*
//Break character styles
BreakCharStyle= app.menuActions.itemByID(8501);
try {
BreakCharStyle.invoke();
}
catch (err){};*/
// app.selection = null;
}
}
}
}
function breakObjects(){
var myElements = myDocument.allPageItems;
var myElement = myElements[0];
myStyleNameText = 0;
myStyleNameGraph = 0;
myObjectStylesNum = 0;
for (i=0; i<myElements.length; i++){
// app.select(myElements[i]);
if(myElements[i].appliedObjectStyle == myDocument.objectStyles.item(myBasicGraphicFrame) || myElements[i].appliedObjectStyle == myDocument.objectStyles.item(myBasicTextFrame)){
switch(myElements[i].appliedObjectStyle.name){
case myBasicTextFrame:
myStyleNameText += 1;
break;
case myBasicGraphicFrame:
myStyleNameGraph += 1;
break;
default:
}
app.select(myElements[i]);
try {
BreakObjStyle.invoke();
}
catch (err){};
}
}
myObjectStylesNum = myStyleNameGraph + myStyleNameText;
return myObjectStylesNum;
}
function reportChanges(){
myReport = "Rapport:\n"
switch (myChangesList.length) {
case 0:
myReport += "Aucun «Basic Paragraph» trouvé.";
break;
case 1:
myReport += myChangesList.length + " «" + myBasicParagraph.replace(/\[|\]/g,'') + "» remplacé :" + "\n" + myChangesList.join("\n");
break;
default:
myReport += myChangesList.length + " «Basic Paragraph» remplacés :" + "\n" + myChangesList.join("\n");
break;
}
switch (myObjectStylesNum) {
case 0:
myReport += "\n---------------------------\n\nAucun style d'objets «Basic» trouvé.";
break;
case 1:
myReport += "\n---------------------------\n\n" + myObjectStylesNum + " styles d'objet (" + myBasicGraphicFrame.replace(/\[|\]/g,'') + "/" + myBasicGraphicFrame.replace(/\[|\]/g,'') + ") transformé.";
break;
default:
myReport += "\n---------------------------\n\n" + myObjectStylesNum + " styles d'objet (" + myBasicGraphicFrame.replace(/\[|\]/g,'') + "/" + myBasicGraphicFrame.replace(/\[|\]/g,'') + ") transformés.";
break;
}
alert(myReport + "\n\n" + myID + "\n" + dateRev);
}
function main(){
app.scriptPreferences.enableRedraw = 0;
breakText();
breakObjects();
reportChanges();
app.selection = null;
app.scriptPreferences.enableRedraw = 1;
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.