10 Replies Latest reply on Jun 4, 2014 6:26 AM by kanaga kumar

    Style name tag

    Learner Learner

      HI All,

       

      Can anybody help me pls i need to place paragraph style names in the margins either it can be anchor box or a separate box.

       

      Im using the below script to get paragraph styles in box but i unable to get the position of paragraph.

       

      var mydoc = app.activeDocument;

      var pstyles = mydoc.allParagraphStyles;

      for (var i= 2; i<pstyles.length;i++){

         

          var cont = pstyles[i].name.toString();

          app.findTextPreferences = NothingEnum.nothing;

          app.findTextPreferences.appliedParagraphStyle = pstyles[i].name;

          var myResults = mydoc.findText();

          var txfm = mydoc.pages.item(0).textFrames.add();

          txfm.geometricBounds = [10,10,50,50];

          txfm.contents = cont;

          txfm.textFramePreferences.insetSpacing = "1";

          txfm.strokeWeight = .5;

          txfm.fit(FitOptions.FRAME_TO_CONTENT);

       

      }

       

       

      Thanks in advance,

      Learner

        • 1. Re: Style name tag
          Jump_Over Level 5

          Hi,

           

          1. create an object style with desired settings

          2. make it anchored is better solution, so anchoredSettingOptions should be set as well

          3. create a new frame at every foundOccurrence.insertionPoints[0];

          4. apply your object style, add contents, fit;

          5. overset text should be excluded (no geoBound)

           

          so exam this:

           

          var mydoc = app.activeDocument;
          var pstyles = mydoc.allParagraphStyles, cont, myResults, txfm,
          mOSt = mydoc.objectStyles.item("mAnchored_PStInfo");
          if (!mOSt.isValid)
                    mOSt = mydoc.objectStyles.add({name: "mAnchored_PStInfo"});
          with (mOSt) {
                    enableAnchoredObjectOptions = true;
                    enableTextFrameGeneralOptions = true;
                    enableStroke = true;
                    textFramePreferences.insetSpacing = 1;
                    strokeWeight = .5;
                    with (anchoredObjectSettings) {
                              spineRelative = true;
                              anchorPoint = AnchorPoint.TOP_RIGHT_ANCHOR;
                              anchoredPosition = AnchorPosition.ANCHORED;
                              anchorYoffset = 0;
                              anchorXoffset = 0;
                              horizontalAlignment = HorizontalAlignment.LEFT_ALIGN;
                              horizontalReferencePoint = AnchoredRelativeTo.PAGE_MARGINS;
                              verticalAlignment = VerticalAlignment.TOP_ALIGN;
                              verticalReferencePoint = VerticallyRelativeTo.CAPHEIGHT;
                              }
                    }
          for (var i= 2; i<pstyles.length;i++){
          
              cont = pstyles[i].name;
              app.findTextPreferences = NothingEnum.nothing;
              app.findTextPreferences.appliedParagraphStyle = cont;
              myResults = mydoc.findText();
                    len = myResults.length;
                    while (len--) {
                              if (myResults[len].parentTextFrames[0] == null) continue;
                              txfm = myResults[len].insertionPoints[0].textFrames.add();
                              currGB = txfm.geometricBounds;
                              txfm.appliedObjectStyle = mOSt;
                              with (txfm) {
                                        geometricBounds = [ currGB[0], currGB[1], currGB[0] + 40, currGB[1] + 150 ];
                                        contents = cont;
                                        fit(FitOptions.FRAME_TO_CONTENT);
                                        }
                              }
          }
          

           

          Jarek

          • 2. Re: Style name tag
            Learner Learner Level 1

            It works fine for me thank you so much Jarek.

             

            Regards,

            Learner

            • 3. Re: Style name tag
              kanaga kumar Level 1

              Hi Jarek,

               

              Is this any possible for character style and paragraph style different in colors. For example paragraph style is "megenta" and character style is "Cyan".

               

              I do not show in more than one style name (do not retain in same style). Is this possible.

               

              Thanks

              kanaga kumar. k

              • 4. Re: Style name tag
                Jump_Over Level 5

                Hi,

                 

                It goes for each paraStyle collected in var pstyles.

                You can modify this and set custom list of styles there,

                i.e. var pstyle = [ mdoc.paragraphStyles.item("style_1"), mdoc.paragraphStyles.item("style_2") ];

                 

                In case of charStyles it is a different story ==> for example: what to do if two charStyles ocurrences found in the same line? Two anchored textFrames at the same place?

                 

                Jarek

                • 5. Re: Style name tag
                  kanaga kumar Level 1

                  Hi Jarek,

                   

                  Thanks for your quick response, paragraph style names sucessfully generated but i need character style also.

                   

                  In this case we have give color identification for based on paragraph styles and character styles.

                   

                  Eg. Paragraph style box is megenta color and charater style box is cyan color.

                   

                  Screen shot 2014-06-03 at 8.01.56 PM.png

                   

                  My Requirement is:

                  Screen shot 2014-06-03 at 8.09.40 PM.png

                  Is this possible? If possible it is very helpful for me.

                   

                  Thanks in advance,

                  kanaga kumar. k

                  • 6. Re: Style name tag
                    Jump_Over Level 5

                    Hi,

                     

                    It is possible, surely.

                    Moreover it is almost done.

                    How is info's textFrame look like depends on objectStyle "mAnchored_PStInfo" settings (add strokeColor there).

                    You could create another objectStyle for characterStyles infos, let say "mAnchored_CStInfo".

                     

                    To run this for char styles modify var declaration to mdoc.allCharacterStyles and apply other objectStyle

                     

                    Jarek

                    • 7. Re: Style name tag
                      kanaga kumar Level 1

                      Hi Jarek,

                       

                      I have change object style and running successfully, but it is generate same character styles again and again.

                       

                      Do not retain in same style, i need only once. My change highlighted bold in script.

                       

                      Screen shot 2014-06-03 at 8.51.38 PM.png

                       

                       

                       

                       

                      -------------------------

                       

                      var mydoc = app.activeDocument; 

                      var cstyles = mydoc.allCharacterStyles, cont, myResults, txfm,

                      mOSt = mydoc.objectStyles.item("TEST"); 

                      if (!mOSt.isValid) 

                                mOSt = mydoc.objectStyles.add({name: "TEST"}); 

                      with (mOSt) { 

                                enableAnchoredObjectOptions = true; 

                                enableTextFrameGeneralOptions = true;

                                enableStroke = true; 

                                textFramePreferences.insetSpacing = 1; 

                                strokeWeight = .5; 

                                with (anchoredObjectSettings) { 

                                          spineRelative = true; 

                                          anchorPoint = AnchorPoint.TOP_RIGHT_ANCHOR; 

                                          anchoredPosition = AnchorPosition.ANCHORED; 

                                          anchorYoffset = 0; 

                                          anchorXoffset = 0; 

                                          horizontalAlignment = HorizontalAlignment.LEFT_ALIGN; 

                                          horizontalReferencePoint = AnchoredRelativeTo.PAGE_MARGINS; 

                                          verticalAlignment = VerticalAlignment.TOP_ALIGN; 

                                          verticalReferencePoint = VerticallyRelativeTo.CAPHEIGHT; 

                                          } 

                                } 

                      for (var i= 1; i<cstyles.length;i++){ 

                       

                          cont = cstyles[i].name; 

                          app.findTextPreferences = NothingEnum.nothing; 

                          app.findTextPreferences.appliedCharacterStyle = cont; 

                       

                       

                          myResults = mydoc.findText(); 

                                len = myResults.length; 

                                while (len--) { 

                                          if (myResults[len].parentTextFrames[0] == null) continue; 

                                          txfm = myResults[len].insertionPoints[0].textFrames.add(); 

                                          currGB = txfm.geometricBounds; 

                                          txfm.appliedObjectStyle = mOSt; 

                                          with (txfm) { 

                                                    geometricBounds = [ currGB[0], currGB[1], currGB[0] + 40, currGB[1] + 150 ]; 

                                                    contents = cont; 

                                                    fit(FitOptions.FRAME_TO_CONTENT); 

                                                    } 

                                          } 

                      --------------------

                       

                      Thanks in advance

                      kanaga kumar. k

                      • 8. Re: Style name tag
                        kanaga kumar Level 1

                        Hi Jarek,

                         

                        I have changed var i=1, please see above for full changed script (pstyle change to cstyle) with screen shot.

                         

                        Could you help me in this regard. It is very urgent. Don't mistake me.

                         

                        for (var i= 1; i<cstyles.length;i++){ 


                        Thanks for advance.

                        kanaga kumar. k

                        • 9. Re: Re: Style name tag
                          Jump_Over Level 5

                          Hi,

                           

                          Here you are:

                          var
                            mydoc = app.activeDocument,
                            pstyles = mydoc.allParagraphStyles, cont, myResults, txfm,
                            cstyles = mydoc.allCharacterStyles,
                            mParaOSt = mydoc.objectStyles.item("mAnchored_PStInfo"),
                            mCharOSt = mydoc.objectStyles.item("mAnchored_CStInfo"),
                            which_P_Occurrence = 0,  // 1 - first      0 or other than 1 - each occurrence
                            which_C_Occurrence = 1;  // 1 - first      0 or other than 1 - each occurrence
                          if (!mParaOSt.isValid)
                            mParaOSt = mydoc.objectStyles.add({name: "mAnchored_PStInfo"});
                          with (mParaOSt) {
                            enableAnchoredObjectOptions = true;
                            enableTextFrameGeneralOptions = true;
                            enableStroke = true;
                            textFramePreferences.insetSpacing = 1;
                            strokeWeight = .5;
                            strokeColor = "blue";
                            with (anchoredObjectSettings) {
                            spineRelative = true;
                            anchorPoint = AnchorPoint.TOP_RIGHT_ANCHOR;
                            anchoredPosition = AnchorPosition.ANCHORED;
                            anchorYoffset = 0;
                            anchorXoffset = 0;
                            horizontalAlignment = HorizontalAlignment.LEFT_ALIGN;
                            horizontalReferencePoint = AnchoredRelativeTo.PAGE_MARGINS;
                            verticalAlignment = VerticalAlignment.TOP_ALIGN;
                            verticalReferencePoint = VerticallyRelativeTo.CAPHEIGHT;
                            }
                            }
                          if (!mCharOSt.isValid)
                            mCharOSt = mydoc.objectStyles.add({name: "mAnchored_CStInfo"});
                          with (mCharOSt) {
                            enableAnchoredObjectOptions = true;
                            enableTextFrameGeneralOptions = true;
                            enableStroke = true;
                            textFramePreferences.insetSpacing = 1;
                            strokeWeight = .5;
                            strokeColor = "red";
                            with (anchoredObjectSettings) {
                            spineRelative = true;
                            anchorPoint = AnchorPoint.TOP_RIGHT_ANCHOR;
                            anchoredPosition = AnchorPosition.ANCHORED;
                            anchorYoffset = 0;
                            anchorXoffset = 0;
                            horizontalAlignment = HorizontalAlignment.LEFT_ALIGN;
                            horizontalReferencePoint = AnchoredRelativeTo.PAGE_MARGINS;
                            verticalAlignment = VerticalAlignment.TOP_ALIGN;
                            verticalReferencePoint = VerticallyRelativeTo.CAPHEIGHT;
                            }
                            }
                          for (var i= 1; i<cstyles.length;i++){
                          
                            cont = cstyles[i].name;
                            app.findTextPreferences = NothingEnum.nothing;
                            app.findTextPreferences.appliedCharacterStyle = cont;
                            myResults = mydoc.findText();
                            if (which_C_Occurrence == 1) len = Math.min(1, myResults.length);
                            else len = myResults.length;
                            while (len-->0) {
                            if (myResults[len].parentTextFrames[0] == null) continue;
                            txfm = myResults[len].insertionPoints[0].textFrames.add();
                            currGB = txfm.geometricBounds;
                            txfm.appliedObjectStyle = mCharOSt;
                            with (txfm) {
                            geometricBounds = [ currGB[0], currGB[1], currGB[0] + 40, currGB[1] + 150 ];
                            contents = cont;
                            fit(FitOptions.FRAME_TO_CONTENT);
                            }
                            }
                          }
                          for (var i= 2; i<pstyles.length;i++){
                          
                            cont = pstyles[i].name;
                            app.findTextPreferences = NothingEnum.nothing;
                            app.findTextPreferences.appliedParagraphStyle = cont;
                            myResults = mydoc.findText();
                            if (which_P_Occurrence == 1) len = Math.min(1, myResults.length);
                            else len = myResults.length;
                            while (len-->0) {
                            if (myResults[len].parentTextFrames[0] == null) continue;
                            txfm = myResults[len].insertionPoints[0].textFrames.add();
                            currGB = txfm.geometricBounds;
                            txfm.appliedObjectStyle = mParaOSt;
                            with (txfm) {
                            geometricBounds = [ currGB[0], currGB[1], currGB[0] + 40, currGB[1] + 150 ];
                            contents = cont;
                            fit(FitOptions.FRAME_TO_CONTENT);
                            }
                            }
                          }
                          app.findTextPreferences = NothingEnum.nothing;
                          
                          

                           

                           

                          Assumed:

                          •      Defined colors "red" and "blue" in active document
                          •      objectStyle for paraStyles is named mAnchored_PStInfo (if not defined ==> script creates it)
                          •      objectStyle for charStyles is named mAnchored_CStInfo (if not defined ==> script creates it)
                          •      set which_P_Occurrence and which_C_Occurrence to determine if info supposed to be repeated for particular style

                           

                          Jarek

                          • 10. Re: Style name tag
                            kanaga kumar Level 1

                            Hi Jarek,

                             

                            Its awesome, Thanks for your help.

                             

                            Thanks

                            kanaga kumar. k