1 Reply Latest reply on Jul 9, 2015 12:14 AM by Laubender

    Overwrite paragraph style when move from style group

    Sudha K



           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

        • 1. Re: Overwrite paragraph style when move from style group
          Laubender Adobe Community Professional & MVP

          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[n].parent.constructor.name === "ParagraphStyleGroup" 
                  && myAllParagraphStyles[n].name === myName){
                  myGroupedStyle = myDoc.paragraphStyles.itemByID(myAllParagraphStyles[n].id);
              if(myAllParagraphStyles[n].parent.constructor.name === "Document" 
                  && myAllParagraphStyles[n].name === myName){
                  myRootStyle = myDoc.paragraphStyles.itemByID(myAllParagraphStyles[n].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:
          //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.