Skip to main content
Inspiring
July 9, 2015
Question

Overwrite paragraph style when move from style group

  • July 9, 2015
  • 1 reply
  • 314 views

Hi,

     If i move the same style name (Paragraph Style 1) from style group its throwing the below error.

But if i move manually its brings the warning dialog as shown below.

How to overwrite the style using script???

Thanks in advance,

Sudha K

This topic has been closed for replies.

1 reply

Community Expert
July 9, 2015

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