Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

CS3 JS – Get all Page Items that have a script label without iterating

Return to Member Forum

  • Author
    Posts
    • #64161
      Brian Pifer
      Participant

      Howdy,

      Is there any way, using pageItems.everyItem() or some other method, to get a collection of all Page Items that have a script label without having to iterate through the entire Page Item collection? I'm writing in JavaScript, and working on CS3.

      Basically, the script would work like so:

      myLabeledItems = myDoc.pageItems.?

      for (item in myLabeledItems) { //do stuff }

      I want to be able to dynamically create and place files based on info (like the date) in the doc name, and the label. If there's a better way than using labels, I'm all ears. Thanks for your help.

    • #64232
      Eugenyus
      Member

      var doc = app.activeDocument;
      var piLabels = doc.pageItems.everyItem().label;
      piLabels.sort();
      var frstLabel = lastLabel = 0;
      do{
      while (piLabels[frstLabel] == piLabels[lastLabel+1]){lastLabel++;}
      if (lastLabel != frstLabel) {
      piLabels.splice(frstLabel, lastLabel-frstLabel+1);
      lastLabel = frstLabel;
      }
      else{
      frstLabel++;
      }
      }while(frstLabel!=piLabels.length-1);
      alert(piLabels.join(“n”)); //Lists the labels without having to iterate…

    • #64417
      Brian Pifer
      Participant

      Thanks for the suggestion, but you still have to touch them all in the sort. I figured out though that that wasn't where the bottleneck in my script was.

Viewing 2 reply threads
  • You must be logged in to reply to this topic.
Forum Ads