2 Replies Latest reply on Apr 6, 2011 3:01 AM by larasachin

    Need script for Marginal Elements consists two tags

    larasachin Level 1

      Hi Everyone,

       

      I need a script for the Marginal Elements having two Paragraph tags. Object Styles, Library items are all availale for this job. My requirement is cut the two paragraph tags and put it in library items and also using object styles as well. Is it possible? Can you help for this. For more clarification i have attached that file also.Screen shot 2011-04-05 at 4.41.13 PM.png

       

       

      Waiting for your reply....

        • 1. Re: Need script for Marginal Elements consists two tags
          Green4ever Level 3

          Hi Try This code.....

           

          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:"Choose Paragraph Style1:", minWidth:myLabelWidth});
                          }
                          with(dialogColumns.add()){
                              myParaStyleDropdown1 = dropdowns.add({stringList:myParaStyleNames, selectedIndex:0});
                              }
                          }
                      //---------
                        with(dialogRows.add()){
                              with(dialogColumns.add()){
                                  staticTexts.add({staticLabel:"Choose Paragraph Style2:", minWidth:myLabelWidth});
                                  }
                              with(dialogColumns.add()){
                                  myParaStyleDropdown2 = 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){
                   myParagraphStyle1 = myParaStyleNames[myParaStyleDropdown1.selectedIndex];
                  myParagraphStyle2 = myParaStyleNames[myParaStyleDropdown2.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.activeDocument;
          var myStory = myDoc.stories;
          var myParas, myCount = 0;
          var myLib = app.libraries[0];
          var AnchorItemName = prompt("Enter the Library Item Name Exactly","","Anchor Item");

          for(i=0; i<myStory.length; i++)
          {
              myParas = myStory[i].paragraphs;
              if (myParas.length>3)
              {
                  for(j=0; j<myParas.length-1; j++)
                  {
                      var firstPara = myParas[j];
                      var nextPara = myParas[j+1];
                      var firstParaStyle = firstPara.appliedParagraphStyle.name;
                      var nextParaStyle = nextPara.appliedParagraphStyle.name;
                      if ((nextParaStyle == myParagraphStyle2)&&(firstParaStyle == myParagraphStyle1))
                      {
                          myText = myLib.assets.item (AnchorItemName).placeAsset (firstPara.insertionPoints[0])[0];
                          firstPara.move(LocationOptions.after, myText.insertionPoints[0]);
                          nextPara.move(LocationOptions.after, myText.insertionPoints[-1]);
                          myText.fit(FitOptions.frameToContent);
                          myCount++;
                          }//End if
                  }//End of Para iteration
              }//End of If paralength>2
              }//End of story iteration
          alert(myCount + " Ocurrences Found and Processed");

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

          Green4ever

          • 2. Re: Need script for Marginal Elements consists two tags
            larasachin Level 1

            Hi Green4Ever,

             

            Awesome reply. Now it works correctly. You save my precious time.

             

            Thanks a lot!!!!!