Copy link to clipboard
Copied
Copy link to clipboard
Copied
You could check, if the style with the same name is already in the root and then replace it without using the move method. The method remove() should be sufficient.
Something like this:
var myDoc = app.documents[0];
var myAllParagraphStyles = myDoc.allParagraphStyles;
var myName = "Paragraph Style 1";
var myRootStyle = null;
var myGroupedStyle = null;
for(var n=0;n<myAllParagraphStyles.length;n++){
if(myAllParagraphStyles
.parent.constructor.name === "ParagraphStyleGroup" && myAllParagraphStyles
.name === myName){ myGroupedStyle = myDoc.paragraphStyles.itemByID(myAllParagraphStyles
.id); };
if(myAllParagraphStyles
.parent.constructor.name === "Document" && myAllParagraphStyles
.name === myName){ myRootStyle = myDoc.paragraphStyles.itemByID(myAllParagraphStyles
.id); };
};
//We assume here, that all went well (the styles were found) and none of the variables returns null as value:
//Otherwise we need some checks.
//1. "Exchange" the root style with the style in the group:
myRootStyle.remove(myGroupedStyle);
//2. Then move the style to the root:
myGroupedStyle.move(LocationOptions.UNKNOWN , myDoc);
One of the tricks here is to get the styles by their ID.
Tested in InDesign CS 5.5 on Mac OSX 10.6.8.
Uwe
Find more inspiration, events, and resources on the new Adobe Community
Explore Now