5 Replies Latest reply on Mar 25, 2012 12:04 AM by Green4ever

    Placing an Marginal elements using object styles

    Learner X Level 1

      Hi,

       

      While i am using this following script i found this error. 

       

      1. Paragraph style = TA

       

      2. Object style = TA

       

      3. Library Name = ANNO

       

       

       

      //Script start from here

       

      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];

       

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

       

          //<<>>myText.appliedObjectStyle = myObjectStyle;

       

          //<<>>myText.contents=myFind[i].contents;

       

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

       

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

       

          myText.fit(FitOptions.frameToContent);

       

          myCount++;

       

      }

       

       

       

       

       

       

       

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

       

       

       

       

      For your more information i attach the file.

       

      Screen Shot 2012-03-20 at 10.51.16 AM.png

       

       

      Please give any solution for above mentioned issues. Where i want to change in this script?

       

      Thanks in advance...