Skip navigation
johneday
Currently Being Moderated

Filter page items by property in Javascript

Aug 9, 2012 8:31 PM

Tags: #javascript #illustrator_pageitems

What is the Javascript equivalent to this AppleScript?

 

set xxx to every page item whose note = "John"

 

After looking at some of the tutorials, I pieced this together. Is there a better way of doing this? With 30,000 path items it took over a minute to execute...

 

docRef = app.activeDocument;

 

var pathLength = docRef.pathItems.length;

 

docRef.pathItems[0].note;

 

var hitList = []

for (i = 0; i<pathLength; i++)

 

{

if (docRef.pathItems[i].note= "John")

{

hitList.push(i)  

}

}

 

alert(hitList.length)

 
Replies
  • Currently Being Moderated
    Aug 9, 2012 10:25 PM   in reply to johneday

    No better way I think, but shouldn’t it be if (docRef.pathItems[i].note == "John") ?

    And if you only want to get length, there is no need for create an array, just increase the count is OK, maybe a little faster.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 9, 2012 10:39 PM   in reply to johneday

    over a minute to process 30,000 items is awsome.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 10, 2012 5:38 AM   in reply to johneday

    myCount++ like you did with i

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points