6 Replies Latest reply on Jun 15, 2011 5:54 PM by Elvissan

    Using allPageItems to find a textFrame using the label gives error

    Elvissan Level 1

      Hello all

      Using allPageItems to find a textFrame using the label gives error.

      Example:
      I have a text frame with the label "myTest"
      The problem that the textFrame can be in a group of objects or not. So I have tosearch using allPageItems.

       

       

      1. I am writing this, but gives error:

       

      var myDocument = app.activeDocument;
      var myTextFrame = myDocument.allPageItems.item("myTest");
      myTextFrame.contents = "Test OK!";
      alert("OK!");
      
      

       

       

      2. Writing this way I can succeed, but may take longer because they can not know how many items in the document:

       

      var myDocument = app.activeDocument;
      var myTextFrame;
      for(var i = 0; i < myDocument.allPageItems.length; i++){
          if (myDocument.allPageItems[i].constructor.name == "TextFrame"){
              if (myDocument.allPageItems[i].label == "myTest"){
                  var myTextFrame = myDocument.allPageItems[i];
                  myTextFrame.contents = "Test OK!";
                  alert("OK!");
                  break;
                  }
              }
          }
      

       

      There is another way that a more direct and quick to find the TextFrame?

       

      I'm using CS4, but I can work using CS5 CS5.5 or if it is better.

       

      Thanks

      Elvis