0 Replies Latest reply on Jun 9, 2009 1:36 AM by dhishok

    place text into frames and apply object style...

    dhishok Level 1

      Hi everyone,

       

      I am creating the script for InDesign CS3 for finding a particular styled paragraphs (i.e. user defined) and placing the library item “ANNO“ i.e. a text frame after the each found paragraphs. Then i have tried to place this paragraphs into corresponding anchored frames. The library items are placed very well. I have tried but the paragraphs are not placed into these anchor frames. The object style is also user defined and it is not applied to these frames. Please look into my below script and do the needful. Also i have attached the library item 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