7 Replies Latest reply on Jun 10, 2009 7:19 PM by dhishok

    find paragraphs by style and it has to be placed as marginal notes...

    dhishok Level 1

      Hi everone,

       

      We have the script to find the paragraphs by its style and cut those paragraphs in the main colomn of the page and paste it into new text frame and this will placed as marginal notes. After putting the first marginal note the script shows error like "Reference not found". Also we need to make this marginal notes as anchored text. Find the script below and suggest me,

       

      //===============

       

      var myDocument = app.activeDocument;

      myDocument.viewPreferences.rulerOrigin=RulerOrigin.pageOrigin;

      myDocument.viewPreferences.horizontalMeasurementUnits=MeasurementUnits.points;

      myDocument.viewPreferences.verticalMeasurementUnits=MeasurementUnits.points;

      myDocument.zeroPoint = new Array(0, 0);

      var mypage = app.layoutWindows[0].activePage.side;

      var mypage2 = app.layoutWindows[0].activePage.name;

      var orientation;

      if (mypage==1919382632)

            orientation="Right";

      else

            orientation="Left";

      try{

      var mySelection=null;

      var mySelection = myDocument.selection[0];

      if (mySelection==null){

            alert("Select any Text Frame then run it");

            exit(0);}

           

      myDocument.textFramePreferences.textColumnCount=1;

      for (i=0; i<mySelection.paragraphs.length;i++)

      {

            if (mySelection.paragraphs[i].appliedParagraphStyle.name=="M-Term")

            {

                  var a=i+1;

                  mySelection.paragraphs[i].select(SelectionOptions.replaceWith);

                  while (mySelection.paragraphs[a].appliedParagraphStyle.name=="M-Def"){

                              mySelection.paragraphs[a].select(SelectionOptions.addTo);

                              a++;}

                  app.cut();

                  if (orientation=="Left")

                        var myframe  = myDocument.pages.item(mypage2).textFrames.add({visibleBounds:["120 pt","42 pt","190 pt","156 pt"], contents:"S"});

                  else

                        var myframe = myDocument.pages.item(mypage2).textFrames.add({visibleBounds:["350 pt","457 pt","438 pt","571 pt"], contents:"S"});

                  myframe.paragraphs[0].select(SelectionOptions.replaceWith);

                  app.paste();

                  myframe.fit(FitOptions.frameToContent);

            }

            }

      }catch(e){alert(e);}

       

      //=====================

       

      Can anyone help me for this.

       

      Thanks in advance...

      Thiyagu

        • 1. Re: find paragraphs by style and it has to be placed as anchor objects...
          dhishok Level 1

          Hi everyone,

           

          I have changed the approach of placing ANNO styled paragraphs in to anchor objects. Now the script is working fine. But the concern is, while placing the ANNO styled paragraphs in the marginal area the script will skip the remaining same styled paragrpahs when it comes more than one in the same occurance.

           

          Example: If two ANNO styled paragraphs are there in one occurance means the script skip the 2nd paragraph.

                          If four ANNO styled paragraphs are there in one occurance means the script skip the 2nd & 4th paragraphs.

           

          Also the same occurance of ANNO styled paragraphs have to be placed in one frame. Instead of this the script place each paragraphs in individual frames. I have tried to fix this but i am unable to do that. Find the script below and help me out.

           

          //============

           

          if(app.documents.length>0)
          {
              var myDoc=app.activeDocument;
              var Style=["ANNO"];
              var LibraryName=["TXT_FRAME"];
              var counter=0;
              var Xoffset=63;
              var Yoffset=4;
              var Dist=12;
             
              alert(myDoc.stories.length);
              var myNewUnits = myDoc.viewPreferences;
              myNewUnits.verticalMeasurementUnits = MeasurementUnits.points;
              myNewUnits.horizontalMeasurementUnits = MeasurementUnits.points;
              myNewUnits.rulerOrigin=RulerOrigin.pageOrigin;
              myDoc.zeroPoint=[0,0];
             
              for(var j=0;j<Style.length;j++)
              {
                  for(var i=myDoc.stories.length-1;i>=0;i--)
                  {
                      var Stry=myDoc.stories[i];
                      var Para=Stry.paragraphs;
                      for(var k=0;k<Para.length;k++)
                      {
                          try
                          {
                              if(Para[k].appliedParagraphStyle.name==Style)
                              {
                                  app.selection=1851876449;
                                  Para[k].select();
                                  app.copy();
                                  app.selection=1851876449;
                                  var y=app.libraries[0].assets;
                                  var Chi=LibraryName[j];
                                  var x=y.item(Chi).placeAsset(myDoc);
                                  Tex=x[0];
                                  Tex.contents="A";
                                  Tex.paragraphs[0].select();
                                  app.paste();
          //                        var RemLen=Tex.characters.length;
          //                        Tex.characters[RemLen-1].remove();
                                  Tex.fit(FitOptions.frameToContent);
                                 
                                  x[0].select();
                                  app.cut();
                                  Para[k].select();
                                  Para[k].characters[0].select(SelectionOptions.addTo);
                                  var CharLen=Para[k].characters.length;
                                  Para[k].characters[CharLen-2].select(SelectionOptions.addTo);
                                  app.paste();
                             
                                  var Obj=Para[k].pageItems[0];
                                  Obj.anchoredObjectSettings.anchoredPosition = AnchorPosition.anchored;
                                  Obj.anchoredObjectSettings.spineRelative=true;
                                  Obj.anchoredObjectSettings.anchorPoint = AnchorPoint.topLeftAnchor;
                                  Obj.anchoredObjectSettings.horizontalReferencePoint=AnchoredRelativeTo.pageMargins;
                                  Obj.anchoredObjectSettings.anchorXoffset=0;
                                  Obj.anchoredObjectSettings.anchorYoffset=0;
                                  Obj.anchoredObjectSettings.verticalReferencePoint=VerticallyRelativeTo.capheight;
                                                     
                                  counter++;           
                              }
                          }
                          catch(e)
                          {
                              alert(e);
                          }
                      }
                  }
              }
              alert(counter+" DONE");
          }

           

          //=====================

           

          Thanks in advance

          Thiyagu

          • 2. Re: find paragraphs by style and it has to be placed as anchor objects...
            Peter Kahrel Adobe Community Professional & MVP

            See comments to your other post here about icons in margin notes. The tasks are virtually identical.

             

            Peter

            • 3. Re: find paragraphs by style and it has to be placed as anchor objects...
              dhishok Level 1

              Hi Peter,

               

               

              As per your suggestions I am creating the script for finding a particular styled paragraphs and placing the library item “ANNO“ (i.e. a text frame) after the each found item. Then i have tried to place those paragraphs into corresponding frames which are placed from the library near to it. The library items are placed very well. But i am unable to place these paragraphs into anchor frames. Unfortunately the object style is also not applied to these frames. Please look into my below script and do the needful. Also i attached the INDD and Library file with this post.


               

               

              //======================

               

              main();
              function main(){
                  if (app.documents.length!=0){
                      if(app.libraries.length!=0){
                      myStyleDialog();
                      }
                      else {
                          alert ("Please open the Library.");
                      }
                  }
                  else {
                      alert ("Please open a document and try again.");
                      exit(0);
                  }
              }

               

              function myStyleDialog(){
              var myLabelWidth = 120;
              var myParaStyleNames = myGetParagraphStyleNames();
              var myObjStyleNames = myGetObjectStyleNames();
              var myDialog = app.dialogs.add({name:"Choose Styles to Place Anchor"});
              with(myDialog.dialogColumns.add()){
                  with(borderPanels.add()){
                      with(dialogColumns.add()){
                          with(dialogRows.add()){
                              with(dialogColumns.add()){
                                  staticTexts.add({staticLabel:"Paragraph Styles:", minWidth:myLabelWidth});
                              }
                              with(dialogColumns.add()){
                                  myParaStyleDropdown = dropdowns.add({stringList:myParaStyleNames, selectedIndex:0});
                                  }
                              }
                                  with(dialogRows.add()){
                                      with(dialogColumns.add()){
                                          staticTexts.add({staticLabel:"Object Styles:", minWidth:myLabelWidth});
                                          }
                                      with(dialogColumns.add()){
                                          myObjectStyleDropdown = dropdowns.add({stringList:myObjStyleNames, selectedIndex:0});
                          }
                      }
                  }
              }
                  myReturn = myDialog.show();
                  if(myReturn == true){
                       myParagraphStyle = myParaStyleNames[myParaStyleDropdown.selectedIndex];
                       myObjectStyle = myObjStyleNames[myObjectStyleDropdown.selectedIndex];
                       myDialog.destroy();
                       }
                    else {
                    myDialog.destroy();
                    }  
                  }
              }
              function myGetParagraphStyleNames(){
                  var myStyleNames = app.documents.item(0).paragraphStyles.everyItem().name;
                  return myStyleNames;
              }   
              function myGetObjectStyleNames(){
                  var myObjStyleNames = app.documents.item(0).objectStyles.everyItem().name;
                  return myObjStyleNames;
              }

               

              var myDoc = app.documents[0];
              var myLib = app.libraries[0];
              app.findTextPreferences = NothingEnum.nothing;
              app.changeTextPreferences = NothingEnum.nothing;
              app.findTextPreferences = null;
              app.findTextPreferences.appliedParagraphStyle=myParagraphStyle;

               

              myFind = myDoc.findText(true);
              var myCount=0;
              for (i=0; i<myFind.length; i++)
              {
                  myText = myLib.assets.item ("ANNO").placeAsset (myFind[i].insertionPoints[-1])[0];
                  myText.insertionPoints[0]=myFind[i].contents;
                  myText.appliedObjectStyle = myObjectStyle;
                  myCount++;
              }

               

              alert(myCount+" ANNOs are Placed Successfully...");

               

              //======================

               


              Thanks in advance

              Thiyagu

              • 4. Re: find paragraphs by style and it has to be placed as marginal notes...
                Peter Kahrel Adobe Community Professional & MVP

                > myText.insertionPoints[0]=myFind[i].contents;

                 

                is not correct. Use myText.contents=myFind[i].contents;

                 

                > myText.appliedObjectStyle = myObjectStyle;

                 

                may not work because myObjectStyle is a string. Instead, apply the style as an object:

                 

                myText.appliedObjectStyle = myDoc.objectStyles.item (myObjectStyle);

                 

                Peter

                1 person found this helpful
                • 5. Re: find paragraphs by style and it has to be placed as marginal notes...
                  dhishok Level 1

                  Hi Peter,

                   

                  Wow it has done a magic. Thanks for your timely support. I have modified the script as you suggested. Its working fine. But the concern is the placed paragraphs all are defaulted to Basic paragraph style and these paragraphs are lose its style formats like paragraph style as well as the character style. The style formats are not retained as the same. So i have tried the copy and paste method to place the contents but it will not work out. Please look into this and help me out. I have placed the part of script below.

                   

                  myFind = myDoc.findText(true);

                  var myCount=0;

                  for (i=0; i<myFind.length; i++)

                  {

                  myText = myLib.assets.item ("ANNO").placeAsset (myFind[i].insertionPoints[-1])[0];

                  myText.contents=myFind[i].contents;

                  myText.appliedObjectStyle = myDoc.objectStyles.item(myObjectStyle);

                  myText.fit(FitOptions.frameToContent);

                  myFind[i].remove();

                  myCount++;

                  }

                   

                  Thanks in advace

                  Thiyagu

                  • 6. Re: find paragraphs by style and it has to be placed as marginal notes...
                    Peter Kahrel Adobe Community Professional & MVP

                    > the placed paragraphs all are defaulted to Basic paragraph style and these paragraphs are lose its style formats like paragraph style as well as the character style. The style formats are not retained as the same.

                     

                    That's because when you do

                     

                    myText.contents=myFind[i].contents;

                     

                    you copy just the text contents, none of the formatting. To get the found items together with their styling, try something like this instead:

                     

                    myFind[i].move (LocationOptions.after, myText.insertionPoints[0]);

                     

                    Naturally, you should then remove the line myFind[i].remove(); because there's nothing left to move.

                     

                    Peter

                    • 7. Re: find paragraphs by style and it has to be placed as marginal notes...
                      dhishok Level 1

                      Hi Peter,


                      Great its working fine. Thank you so much. With your help i have completed my script successfully. I am too happy now.

                       

                      Thanks

                      Thiyagu