3 Replies Latest reply on Apr 7, 2011 1:33 AM by John Hawkinson

    Get textFrame by label returns null and anchored objects

    xmlapi

      I have the following two functions:

      function getByLabel(page, label)
      {
          for(var i=0; i < page.allPageItems.length; i++)
          {
              if( page.allPageItems[i].label == label )
              {
                  return page.allPageItems[i];
                 }
              }
      }

       

      and

       

      Object.prototype.findItems = function(/*obj*/props)
      {
          if( !('everyItem' in this) )
              {
              throw new Error("Error: " + this + " is not a collection.");
              }

          var ret = this.everyItem().getElements(),
              i = ret.length,
              e, p;

          while( i-- && e=ret[i] )
              {
              for( p in props )
                  {
                  if( (p in e) && e[p]===props[p] ) continue;
                  ret.splice(i,1);
                  }
              }
          return ret;
      };

       

       

       

      In my page structure, I got one main text frame (the content area) and two vertical text fromes on the sides of the page. There is also a small box textframe on top of the page. All these textboxes EXCEPT the main text frame are ALL "ANCHORED objects". I had to make them anchored objects, eitherwise after importing data, the boxes would jump around. (Example, the small box textframe that is on the top would get moved to the content area textframe etc). Not sure if using anchored objects is the proper way to fix this.

       

      When I try to get the small box text frame, it does not work using the findItems (returns null) but it works fine with the getByLabel method. Why is that?

       

      The calling syntax is:

       

      for( i=0 ; i < doc.pages.length ; ++i )
          {
              var page = doc.pages.item(i);
              var textFrame = getByLabel(page, 'lblSection' ); //This works

              //   var textFrame = page.textFrames.findItems({ label:  'lblSection' })[0]; This does not work, returns null
              if( textFrame != null )
              {

                  textFrame.parentStory.contents = "";
               }
          }