8 Replies Latest reply on May 23, 2013 5:13 AM by lcooperdesign85

    Selected elements from list to separate text frame

    lcooperdesign85

      Hi,

       

      Could somebody please help find a solution to this? In the linked picture you will see a numbered list with each line in the list starting with a 4 digit code (magenta), there is also a colour identifyer in the form of a single capital letter (orange). I need to take these parts only from each line and created a single string separated by underscores as shown in the attached file.

       

      Would this be possible do you think? If so, how could it be done?

       

      Your help will be greatly appreciated!

       

      Screen Shot 2013-05-22 at 17.02.40.png

        • 1. Re: Selected elements from list to separate text frame
          Jump_Over Level 5

          Hi,

           

          If your sourceTextFrame is named "source"

          and your outputTextFrame is named "output"

          you can use it (or change the way of detecting text frames):

           

          var mDoc = app.activeDocument;
          var source = mDoc.textFrames.item("source");     // this name should be shown in "Layer" panel
          var output = mDoc.textFrames.item("output");    // this name should be shown in "Layer" panel
          var mLine, part1, part2;
          
          for (k = 0; k< source.parentStory.lines.length; k++) {
              mLine = source.parentStory.lines[k];
              app.findGrepPreferences = null;
              app.findGrepPreferences.findWhat = "^.{4}";
              part1 = mLine.findGrep();
              app.findGrepPreferences.findWhat = "\\u(?=\\.)";
              part2 = mLine.findGrep();
              part1[0].duplicate(LocationOptions.AT_END, output.parentStory);
              part2[0].duplicate(LocationOptions.AT_END, output.parentStory);
              output.parentStory.insertionPoints[-1].contents = "_";
              }
          output.parentStory.characters[-1].remove();
          output.parentStory.paragraphs[0].bulletsAndNumberingListType = ListType.NO_LIST;
          

          rgds

          Jarek

          1 person found this helpful
          • 2. Re: Selected elements from list to separate text frame
            lcooperdesign85 Level 1

            Hi Jump_Over,

             

             

            Thank you very much for the reply. This looks promising, however I could not get it to work. I named the source text frame 'source' in the 'script label' panel and likewise the output as 'output'. but I recieved this error:

             

            Screen Shot 2013-05-23 at 09.58.32.png

             

            Ideally though, the script would be able to identify the 'source' and 'output' textframes by their relative positions, i.e. source will always be above output.

             

            Is there a way I could select both frames and then execute the script?

            • 3. Re: Selected elements from list to separate text frame
              Jump_Over Level 5

              Hi,

               

              use "Layer" panel to name the boxes

               

              Jarek

              1 person found this helpful
              • 4. Re: Selected elements from list to separate text frame
                lcooperdesign85 Level 1

                Ahhh, who'd of thought you could expand the layer and see its contents.

                 

                Right, so I got this to work, thanks Jarek, but this would require me to select each 'source' frame and rename it as 'source' in the layers panel, which unfortunately is not practical in this 100 page document. Currently they have all been named as whatever is inside the textframe.

                 

                 

                 

                Is there not a way I can select the two frames and have the lowest frame filled with the results from the top?

                 

                Thanks for your help and patience,

                Lewis

                • 5. Re: Selected elements from list to separate text frame
                  Jump_Over Level 5

                  Hi,

                   

                  are any other frames on each page then these two?

                  are they placed on the same position (x,y)?

                   

                  describe the way of detect them and I will modify this

                   

                  Jarek

                  1 person found this helpful
                  • 6. Re: Selected elements from list to separate text frame
                    lcooperdesign85 Level 1

                    Unfortunately there are many other text frames on each page (see original screen shot), so would be good to be able to select the boxes needed first then run the script. They are always in the same position though, i.e. the 'source' will always be higher up on the y axis than the 'output'.

                     

                     

                    So ideal workflow would be:

                     

                    1. Select the two text frames (source frame will be above the output frame).

                    2. Execute script (will assign keyboard shortcut).

                    3. Result appears in the bottom text frame.

                     

                    Thank you so much,

                    • 7. Re: Selected elements from list to separate text frame
                      Jump_Over Level 5

                      Hi,

                       

                      OK. Replace these lines:

                      var source = mDoc.textFrames.item("source");
                      var output = mDoc.textFrames.item("output");

                       

                      with:

                      if (app.selection.length != 2) exit();
                      
                      if (app.selection[0].geometricBounds[0] < app.selection[1].geometricBounds[0]) {
                      
                           var source = app.selection[0];
                           var output = app.selection[1];
                      } else {
                           var source = app.selection[1];
                           var output = app.selection[0];
                           }
                      

                       

                      Jarek

                      • 8. Re: Selected elements from list to separate text frame
                        lcooperdesign85 Level 1

                        You sir, are a gentleman!

                         

                        Thank you very much, this has helped me immensely!