• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Filter page items by property in Javascript

New Here ,
Aug 09, 2012 Aug 09, 2012

Copy link to clipboard

Copied

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.note= "John")

{

hitList.push(i)  

}

}

alert(hitList.length)

TOPICS
Scripting

Views

976

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Enthusiast ,
Aug 09, 2012 Aug 09, 2012

Copy link to clipboard

Copied

No better way I think, but shouldn’t it be if (docRef.pathItems.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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 09, 2012 Aug 09, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 10, 2012 Aug 10, 2012

Copy link to clipboard

Copied

So like this?

docRef = app.activeDocument;

var pathLength = docRef.pathItems.length;

docRef.pathItems[0].note;

var myCount = 0

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

{

if (docRef.pathItems.note== "JD")

{

myCount = myCount + 1

}

}

alert(myCount)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Aug 10, 2012 Aug 10, 2012

Copy link to clipboard

Copied

LATEST

myCount++ like you did with i

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines