Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
1

Overwrite paragraph style when move from style group

Contributor ,
Jul 08, 2015 Jul 08, 2015

Hi,

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

Screen shot 2015-07-08 at 1.55.47 PM.png

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

Screen shot 2015-07-08 at 2.08.37 PM.png

How to overwrite the style using script???

Thanks in advance,

Sudha K

TOPICS
Scripting
313
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 09, 2015 Jul 09, 2015
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines