3 Replies Latest reply on Aug 9, 2018 7:52 AM by Peter Kahrel

    Move parent frames using grep search

    ArtGSki Level 1

      I will appreciate anyone that can point me in the right direction, my eyes are crossing from looking at scores of pages looking for solutions—probably in front of my nose.

       

      Background:

      We create ID pages by importing an XML file which is generated from our database. Photos and text/copy populate the page in individual frames from the fields in the database. However, empty fields in the database create frames as well. While they have no "real" content they do have some invisible tag characters.

       

      My problem:

      This is part of a larger script but for the moment my main concern is just some way for the script to distinguish between the "empty" frames and ones with live content (actual text characters) so these boxes can been moved to the pasteboard for possible future use.

       

      If it's of any value, their constructor attribute is "TextFrame" BUT under the "Object/Content" menu, all is greyed out (no option to choose text, graphic, or unassigned, this is true regardless of whether the frames contain actual live content or not)

       

      Below are two strategies I have tried:

       

      1.   **********************************

      //This only moves completely overset text frames (which I don't want) and empty text boxes created in Indesign manually which is not relevant. It does not move any of the XML generated "empty" frames.

       

          var myStories = app.activeDocument.stories.everyItem().getElements();

      for (i = myStories.length - 1; i >= 0; i--){

          var myTextFrames = myStories[i].textContainers;

          for (j = myTextFrames.length - 1; j >= 0; j--)    {

              if (myTextFrames[j].contents == ""){

                  myTextFrames[j].move([-2, 0]);

              }

          }

      }

       

      2.   **********************************

      I have used the script below with success in other scripts. However to capture text frames with no real characters I tried using the regex expression "\A\Z". This WORKS in the Indesign Find/Change utility, but when I use this expression for ".findWhat = '\A\Z';" it returns the alert "Error Number:21 Error String: undefined is not an object"

       

      // Find empty text boxes and move

          app.findGrepPreferences = NothingEnum.nothing;

          app.changeGrepPreferences = NothingEnum.nothing;

          app.findChangeGrepOptions.properties = {includeFootnotes:false, includeHiddenLayers:false, includeMasterPages:true};

          app.findGrepPreferences.findWhat = '\A\Z';

       

          var noText = document.findGrep();

          var noTextFrame = noText[0].parentTextFrames[0];

         

      // Move empty frame

      noTextFrame.move([-2, 0]);

         

      //Reset Grep parameters to null

          app.findGrepPreferences = NothingEnum.nothing;

          app.changeGrepPreferences = NothingEnum.nothing;

      **********************************

      Thanks in advance