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

With CS5, some things have changed

LEGEND ,
Apr 12, 2010 Apr 12, 2010

Copy link to clipboard

Copied

This discussion is for changes to the scripting DOM which can affect legacy scripts.

Please use this discussion for discussing new scripting features in CS5.

Please keep in mind that all changes are specific to version 7 DOM. InDesign supports versioning, so you should be able to use legacy scripts in CS5 without issues. Versioning can be done in two ways:

1) Place the script in a folder named: "Version 6.0 Scripts" (or 5.0, 4.0, 3.0). The folder must be named exactly as specified.

2) Set the script version preferences at the start of your script. (i.e. app.scriptPreferences.version = 6), but it's highly recommended to reset the scripting version at the end of the script, and even to enclose the script in a try/catch/finally block to ensure that the script preferences are reset correctly.

Here's quick links to issues brought up in this thread:

  1. PageItem.parent
  2. PageItem.itemByName()
  3. PageItem.cornerOption and PageItem.cornerRadius
  4. Text values returned as Strings instead of Numbers
  5. PointType.LINE_TYPE was changed to PointType.PLAIN
  6. PasteBoardPreference.minimumSpaceAboveAndBelow was removed.

Harbs

TOPICS
Scripting

Views

57.6K

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
LEGEND ,
Apr 12, 2010 Apr 12, 2010

Copy link to clipboard

Copied

Here's the first two (and probably the most significant) of the changes:

1) PageItem.parent: In previous versions, the parent of top-level page items were the Page that the PaeItem resided on. In CS5, this was changed (for increased performance), and the parent is now the PageItem's Spread. Together with this change, a new property "PageItem.parentPage" was added which returns the page that the PageItem is drawn on. parentPage works for nested PageItems as well, so this new property will do away with the need for a lot of the "findPage" functions that we've all been using!

2) PageItems.itemByName(): With the new layers panel comes a name property for PageItems. In previous versions PageItems.itemByName() would return the page item with the specified label in CS5, it will return the page item with the specified name (which can be set in the Layers Panel). There is no longer a quick-and-easy way to get page items by their label using the 7.0 scripting DOM.

Harbs

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
Participant ,
Apr 12, 2010 Apr 12, 2010

Copy link to clipboard

Copied

2) PageItems.itemByName(): With the new layers panel comes a name property for PageItems. In previous versions PageItems.itemByName() would return the page item with the specified label in CS5, it will return the page item with the specified name (which can be set in the Layers Panel). There is no longer a quick-and-easy way to get page items by their label using the 7.0 scripting DOM.

Does this affect only JS scripts, or all scripting? I do Applescripting and we have A LOT of workflow that depends on item labels. Will this change for Applescripting?

Chris

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
Advocate ,
May 06, 2010 May 06, 2010

Copy link to clipboard

Copied

Chris,

I expect that AppleScript users can still take advantage of whose clauses to get at the label (provided they can master the syntax).

In JavaScript, the news is worse than I feared because you can't even use versioning to get around this. All scripts that use item("label") to get at stuff will have to be rewritten.

Dave

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
LEGEND ,
May 06, 2010 May 06, 2010

Copy link to clipboard

Copied

Dave,

Did you try my suggestion to use blabla.item("bla").getElements()[0] with versioning to resolve the object with versioning?

Harbs

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
Advocate ,
May 07, 2010 May 07, 2010

Copy link to clipboard

Copied

Harbs,

I think I must be wrong about this because to my immense surprise your code works -- my surprise is caused by the certainty that that's just what I tried when I concluded it didn't work. I just did this:

1. I created a new document in CS5.

2. I dragged out a text frame and labeled it "Fred".

3. I duped that twice.

4. I ran this script:

var myDoc = app.documents[0];
var myTFs = myDoc.textFrames.item("Fred");
alert(myTFs == null);
app.scriptPreferences.version = "6.0"
var myTFs = myDoc.textFrames.item("Fred").getElements();
app.scriptPreferences.version = "7.0"
alert(myTFs.length);

There's a caveat here. The end result is an array and not a collection. But presumably the getElements() part is optional. Let me try another experiment. Aha! No it's not optional. This might well explain my confusion. This works:

var myDoc = app.documents[0];
app.scriptPreferences.version = "6.0"
var myTFs = myDoc.textFrames.item("Fred");
alert(myTFs.toSource());
app.scriptPreferences.version = "7.0";

But this doesn't:

var myDoc = app.documents[0];
app.scriptPreferences.version = "6.0"
var myTFs = myDoc.textFrames.item("Fred");
app.scriptPreferences.version = "7.0";
alert(myTFs.toSource());

So, if you create an object reference while working within the CS4 versioning engine it won't work when you move back into the CS5 engine. So, by converting to an array--by using getElements()--which is a core feature, you can pass objects effectively from one engine to the other.

So, if you were converting your collection to an array anyway, then this makes converting the script a whole lot easier than I had feared. On the other hand, if you were using the reference as a collection, then you need to stay within the CS4 versioning engine for it to work. I wonder if you can move in and out of versions ... Yes!

var myDoc = app.documents[0];
app.scriptPreferences.version = "6.0"
var myTFs = myDoc.textFrames.item("Fred");
app.scriptPreferences.version = "7.0";
// some code so that something happens while we're in this engine
for (var j = 0; myDoc.textFrames.length > j; j++) {
     myDoc.textFrames.fillColor = myDoc.swatches[-1];
}
app.scriptPreferences.version = "6.0"
alert(myTFs.toSource());
app.scriptPreferences.version = "7.0";

Well, this isn't as bad as I feared, but I can see me having to add a lot of versioning statements to scripts I convert from CS4 to CS5

Thanks for pointing me in the right direction Harbs.

Dave

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
LEGEND ,
May 07, 2010 May 07, 2010

Copy link to clipboard

Copied

Hi Dave,

Glad it worked. I really would have been surprised if it didn't!

This is the good old referencing problem. Besides giving you and array, getElements() resolves the specifier to the object, so until you use getElements(), the specifier is equivalent to ".item()" which has a different meaning in the 7.0 DOM. After using getElements(), the specifier(s) is (are) resolved to the equivalent of ".itemByID()", which will always give you the correct object(s).

Harbs

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
Advocate ,
May 06, 2010 May 06, 2010

Copy link to clipboard

Copied

> Will this change for Applescripting?

Yes. To refer by item, you should use something like:

item 1 of all page items whose label is "whatever"

A lot of people have been using this sort of construction anyway, to deal with the possibility of grouping, so they should be largely unaffected.

The other thing to keep in mind is that versioning solves the problem for AppleScript.

--

Shane Stanley <sstanley@myriad-com.com.au>

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 ,
Jan 25, 2011 Jan 25, 2011

Copy link to clipboard

Copied

I know this is an ancient post but just wondering if you got an answer on how to talk to boxs that have labels in CS5 I am just returning to the workforce and the last scripts I worked on were CS2 and my new company uses CS5. I'll repost my question below if you have any insights that would be great since we seem to have been in the same boat!

I wrote an Applescript at home on my laptop where I only have Adobe CS2 and want to use the same thing at work to show my boss what is possible with Applescript and it is failing at work cause we have Adobe CS5. Specifically placing a picture in InDesign.

This works in CS2 where I am talking to a named picture box

set picToPlace to "ARTWORK:Close Ups:05-02-04:CUA2222.tif" as alias

tell application "Adobe InDesign CS2"

activate

tell document 1

place picToPlace on rectangle "photo1"

fit rectangle "photo1" given proportionally

end tell

end tell

But at work when it gets to the {place picToPlace on rectangle "photo1"} line it stops and says something about "cannot get alias" (and gives the whole path to the file I am trying to place.)

Have they changed the wording for placing a pic in a rectangle? in CS5?

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
Advocate ,
Jan 25, 2011 Jan 25, 2011

Copy link to clipboard

Copied

Instead of 'rectangle "photo1"', you need to use 'rectangle 1 whose label is "photo1"'.

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
Participant ,
May 07, 2010 May 07, 2010

Copy link to clipboard

Copied

I am not a great scripting hero but i just have one question.

I have a Indesign file wich has a bunch of pages.

On each page there is a textframe wich is labelled "textcode".

When i run the script, Indesign exports each page to a pdf giving the name what's in the labelled textframe.

The problem is, i think, the line:

f = File (myFolder + "/" + p.textFrames.item ('textcode').contents + ".pdf");

Wich contains textFrames.item.

Does anybody knows what i have to change to let it work in CS5?

Already thanks for everyone who wants to help,

Regards,

Bert

Holland

Update: Sorry guys, wasn't reading good. So the problem is solved!

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
LEGEND ,
May 09, 2010 May 09, 2010

Copy link to clipboard

Copied

FWIW,

Here's a general purpose function which gives pre-CS5 behavior for getting items by label using Dave's versioning method:

function GetItemFromCollection(label,collection){
    var scriptVersion = app.scriptPreferences.version;
    if( parseFloat(scriptVersion) > 6){app.scriptPreferences.version = 6}
    var items = collection.item(label).getElements();
    app.scriptPreferences.version = scriptVersion;
    if(items.length==0){return null}
    if(items.length==1){return items[0]}
    return items;
}

To use it you'd do something like this:

items = GetItemFromCollection("test",app.documents[0].pageItems);

If you prefer prototype methods, you can use a function like this:

PageItems.prototype.itemByLabel = function(label){
    var scriptVersion = app.scriptPreferences.version;
    if( parseFloat(scriptVersion) > 6){app.scriptPreferences.version = 6}
    var items = this.item(label).getElements();
    app.scriptPreferences.version = scriptVersion;
    if(items.length==0){return null}
    if(items.length==1){return items[0]}
    return items;
}

However keep in mind that you'd need to do this for each type of collection, and you cannot create prototype functions on collections until you initialize the collection. To do that you'd need to insert a line like this (assuming there's a document open):

app.documents[0].pageItems

You could then write:

items = doc.pageItems.itemByLabel("test");

Harbs

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
Enthusiast ,
Aug 21, 2010 Aug 21, 2010

Copy link to clipboard

Copied

I think it's worth noting doc.pagestextFrames.item("Label") still works. It's only if you try to get the item from the document object where it doesn't work anymore.

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
LEGEND ,
Aug 21, 2010 Aug 21, 2010

Copy link to clipboard

Copied

Good point. That's beacuse there's no name property for pages yet.

However, I think the issue with PageItems in CS5 drives home the point that it's not the best idea to use .item() with labels...

Who knows when Pages might get a name property...

Harbs

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
People's Champ ,
Feb 05, 2011 Feb 05, 2011

Copy link to clipboard

Copied

Hi,

Harbs wrote:

Here's the first two (and probably the most significant) of the changes:

1) PageItem.parent: In previous versions, the parent of top-level page items were the Page that the PaeItem resided on. In CS5, this was changed (for increased performance), and the parent is now the PageItem's Spread. Together with this change, a new property "PageItem.parentPage" was added which returns the page that the PageItem is drawn on. parentPage works for nested PageItems as well, so this new property will do away with the need for a lot of the "findPage" functions that we've all been using!

Is this the case even if I use script versioning? In other words, will CS5 return a Spread for textFrameX.parent even if I included versioning to make it be like CS4?

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
LEGEND ,
Feb 05, 2011 Feb 05, 2011

Copy link to clipboard

Copied

Hi Ariel,

Yes. We discussed this above:

http://forums.adobe.com/message/2800152#2800152

Harbs

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
Enthusiast ,
Mar 29, 2011 Mar 29, 2011

Copy link to clipboard

Copied

Hi Harbs,

2) PageItems.itemByName(): With the new layers panel comes a name property for PageItems. In previous versions PageItems.itemByName() would return the page item with the specified label in CS5, it will return the page item with the specified name (which can be set in the Layers Panel). There is no longer a quick-and-easy way to get page items by their label using the 7.0 scripting DOM.

I can able to access a pageItem directly by its name instead of their label.

For example by using the following code I can able to access a textFrame directly by its name (which is already set in the layers panel).

var mytextFrame = app.activeDocument.pages.item(0).textFrames.item("FirstTextFrame");

alert(mytextFrame.contents);

---------

Green4ever

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
LEGEND ,
Mar 30, 2011 Mar 30, 2011

Copy link to clipboard

Copied

Yes, that is the point. But prior to CS5 you used to be able to use the script label as the parameter, and now you cannot.

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
Enthusiast ,
Mar 31, 2011 Mar 31, 2011

Copy link to clipboard

Copied

Hi All,

I have included glue code.jsx in my CS5 Scripting project.

Because of this app.scriptPreferences.version = 6 command, textFrame.name property becomes invalid in CS5 scripting.

FYI...... I got the "glue code.jsx" from the "XML Rules" folder.

I think, Since there is no changes made to xml objects, the version of this script is not changed. Can I change it to version = 7 or is there anyother way to overcome this problem?]

--------------

Green4ever

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
LEGEND ,
Apr 12, 2010 Apr 12, 2010

Copy link to clipboard

Copied

PageItem.cornerOption and PageItem.cornerRadius is gone.

Instead there's now: bottomLeftCornerOption, bottomRightCornerOption, topLeftCornerOption, and topRightCornerOption. The same for cornerRadius. This is to support the new live corner features.

Harbs

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
Advocate ,
May 06, 2010 May 06, 2010

Copy link to clipboard

Copied

I'm not so sure that the .parentPage property does away with the need for findPage. I was just working on it right now and came to the conclusion that for a general function, it just changes it a bit:

function findPage(theObj) {
     if (theObj.hasOwnProperty("baseline")) {
          theObj = theObj.parentTextFrames[0];
     }
     while (theObj != null) {
          if (theObj.hasOwnProperty ("parentPage")) return theObj.parentPage;
          var whatIsIt = theObj.constructor;
          switch (whatIsIt) {
               case Page : return theObj;
               case Character : theObj = theObj.parentTextFrames[0]; break;
               case Footnote :; // drop through
               case Cell : theObj = theObj.insertionPoints[0].parentTextFrames[0]; break;
               case Note : theObj = theObj.storyOffset; break;
               case Application : return null;
          }
          if (theObj == null) return null;
          theObj = theObj.parent;
     }
     return theObj
} // end findPage

I believe that this function will work with any version of InDesign because it will behave the same as before in versions that don't support the parentPage property.

Of course, if you know you're dealing with an object that has a parentPage property in CS5, you can just go straight for the property.

Dave

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 ,
May 06, 2010 May 06, 2010

Copy link to clipboard

Copied

I believe that this function will work with any version of InDesign because it will behave the same as before in versions that don't support the parentPage property.

I think it won't because of this line:

               case Character : theObj = theObj.parentTextFrames[0]; break;

In CS1 it's ParentTextFrame - one item - not array/collection.

robin

www.adobescripts.co.uk

â–’â–º ID-Tasker / ID-Tasker Server - work smart not hard â—„â–’

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
Advocate ,
May 06, 2010 May 06, 2010

Copy link to clipboard

Copied

Dave,

Aren't you ignoring items on the pasteboard there?

--

Shane Stanley <sstanley@myriad-com.com.au>

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
Advocate ,
May 07, 2010 May 07, 2010

Copy link to clipboard

Copied

Shane,

In the function? Yes -- by definition, they're not on a page. So, they'll return null.

Dave

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 ,
Jul 26, 2010 Jul 26, 2010

Copy link to clipboard

Copied

Hey Dave,

you forgot to handle placed XML Elements in your findPage function and made a mistake about the Cell case.

With a selected Cell your switch statement selected the parentTextFrame and breaked the switch. After the break it would run into line

          theObj = theObj.parent;

The parent of pageItem gives you the Spread in InDesign CS5. I've found it wondering why my xml additon does not worked.

I hope i've not introduced new Bugs

function findPage(theObj) {
     if (theObj.hasOwnProperty("baseline")) {
          theObj = theObj.parentTextFrames[0];
     }
     while (theObj != null) {
          if (theObj.hasOwnProperty ("parentPage")) return  theObj.parentPage;
          var whatIsIt = theObj.constructor;
          switch (whatIsIt) {
               case Page : return theObj;
               case Character : theObj = theObj.parentTextFrames[0]; break;
               case Footnote :; // drop through
               case Cell : theObj = theObj.insertionPoints[0].parentTextFrames[0]; break;
               case Note : theObj = theObj.storyOffset.parentTextFrames[0]; break;
               case XMLElement :  if (theObj.insertionPoints[0] != null) { theObj =  theObj.insertionPoints[0].parentTextFrames[0]; break; }
               case Application : return null;
               default: theObj = theObj.parent;
          }
          if (theObj == null) return null;
     }
     return theObj
} // end findPage


regards,

gregor

UPDATE: made an addition to the Note case  ...

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