1 Reply Latest reply on Jun 29, 2015 7:07 AM by Sajeev Sridharan

    How to search string in layout window and paste inside the element?

    vidhyar34646163 Level 1

      I'm new to indesign stuffs. Am learning extendscript for automation.

       

       

      I need to paste a copied string in the place of `<media>`element in the layout window like the picture below.

      inde.JPG

      But I don't know how to do findgrep in layout window(ctrl+y) rather than editor.

      I have a script for copy-paste into the active document at the specific position of specfic string. But,I need to paste in between the element of `<media></media>`.

       

      For example:  

      If searched string="FIG. 1.1", then I want the copied string to be pasted in the document like below

       

      LAYOUT WINDOW:

       

          <media.block id="fig001"><media></media>

          <caption aid:pstyle="Caption"><num>FIG. 1.1&#x2002;</num>

          <para><txt>The range of disciplines engaged in research and development

          in the field of nanoscience and technology.</txt></para></caption> </media.block>

       

      OUTPUT:

          <media.block id="fig001"><media>*PASTE STRING*</media>

          <caption aid:pstyle="Caption"><num>FIG. 1.1&#x2002;</num>

          <para><txt>The range of disciplines engaged in research and development

          in the field of nanoscience and technology.</txt></para></caption> </media.block>

       

      I have a script to paste into the active document rather than layout window.

       

          app.open(File(myFigDoc)); 

          app.activeDocument.pageItems.everyItem().select(); 

          app.copy(); 

          app.activeDocument.close();

          app.findGrepPreferences = app.changeGrepPreferences = null; 

          var figString="FIG. "+chapno+"."+j;

          app.findGrepPreferences.findWhat = figString;//Figure caption text 

          //app.findGrepPreferences.appliedParagraphStyle = "FigureCaption";//Figure Caption Style 

          myFinds = app.activeDocument.findGrep(); 

          for(var i=0;i<myFinds.length;i++){ 

              myFinds[i].insertionPoints[0].contents="\r"; 

              myFinds[i].insertionPoints[0].select(); 

              app.paste(); 

          }

      how to do it in the layout window?

        • 1. Re: How to search string in layout window and paste inside the element?
          Sajeev Sridharan Level 4

          Try this,

           

          app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
          
          
          var myDoc = File("/D/template-sample.indd");//Figure File
          var myFigDoc = File("/D/fig1.indd");//Destination File
          
          
          app.open(File(myFigDoc));
          app.activeDocument.pageItems.everyItem().select();
          myObj = app.selection;
          app.copy();
          
          
          app.open(File(myDoc));
          app.findGrepPreferences = app.changeGrepPreferences = null;
          app.findGrepPreferences.findWhat = "FIG. 1.1";//Figure caption text
          app.findGrepPreferences.appliedParagraphStyle = "Caption";//Figure Caption Style
          myFinds = app.activeDocument.findGrep();
          alert(myFinds.length)
          for(var i=0;i<myFinds.length;i++){
              var mediaTag = myFinds[i].associatedXMLElements[0].parent.parent.xmlElements[0];
              mediaTag.insertionPoints[0].select();
              app.paste();
          }
          app.findGrepPreferences = app.changeGrepPreferences = null;