Skip to main content
Participating Frequently
April 30, 2009
Answered

[CS3] [JS] error "everyItem() is not a function"

  • April 30, 2009
  • 4 replies
  • 1189 views

I am trying to adapt Dave Saunder's ChangeCaseOfSelectedParaStyle to work with CS3 an CS4 natively without versioning. See code extract below:

myDoc = app.activeDocument;

myStyles = myDoc.allParagraphStyles;

myStringList = myStyles.everyItem().name;

However this throws the following error: myStyles.everyItem is not a function

Any ideas? (or Dave, if you see this have you already have an adapted version).

Nye

This topic has been closed for replies.
Correct answer Peter Kahrel

JavaScript is case-sensitive: use myDoc.paragraphStyles, not myDoc.ParagraphStyles

Peter

4 replies

Harbs.
Legend
April 30, 2009

Of course this will not work if there are style groups.

If there are style groups you need allParagraphStyles and to get their

names you'll need to loop through the array.

myStringList = [];

for(idx=0;idx<myStyles.length;idx++){

myStringList.push(myStyles[idx].name);

}

Harbs

http://www.in-tools.com

EDIT: I responded en route by email. I just noticed Dave's earlier response now...

Message was edited by: Harbs.

Inspiring
April 30, 2009

The original script was written for the long-ago world where all paragraph styles were directly accessible from the Document object. Starting with CS3, this is no longer the case. These days, to get the names of all paragraph styles you need something like this:

var myDoc = app.documents[0];

var myStyles = myDoc.allParagraphStyles;

var stringList = new Array();

for (var j = myStyles.length - 1; j >= 0; j--) {

     stringList.push(myStyles.name);

}

stringList.sort();

Dave

Participating Frequently
April 30, 2009

@ Dave

Thanks for your help, but after correcting the captialisation to document.paragraphStyles that Peter pointed out, and some updates to the Find/Change lines to bring it up to date, the script appears to work correctly in CS3 and CS4. The code you suggest does not seem to be necessary at this time.

By-the-way, many thanks for this great script, along with 'ProtectLocalFormating', we use it all the time in our design studio. I have also made a version of it to work with character styes, and along with grep, they make a powerful combination....

Nye

Inspiring
April 30, 2009

As long as you don't use style groups in CS3 you'll be fine with the original version.

Dave

Participating Frequently
April 30, 2009

Thanks Peter. I am used to the Applescript compiler that sorts out little problems like this!

Peter Kahrel
Community Expert
Community Expert
April 30, 2009

You need this:

myDoc = app.activeDocument;

myStyles = myDoc.paragraphStyles;

myStringList = myStyles.everyItem().name;

myDoc.allParagraphStyles returns an array, while everyItem() is a method that is applied to collections (myDoc.paragraphStyles returns a collection).

Peter

Participating Frequently
April 30, 2009

Thanks Peter, that is how Dave's script was originally, but that was throwing the error :

Object does not support the property of method 'ParagraphStyles'

on the line : myStyles = myDoc.ParagraphStyles;

Now I'm completely confused!? Nye

Peter Kahrel
Community Expert
Peter KahrelCommunity ExpertCorrect answer
Community Expert
April 30, 2009

JavaScript is case-sensitive: use myDoc.paragraphStyles, not myDoc.ParagraphStyles

Peter