Skip to main content
Harbs.
Legend
April 12, 2010
Question

With CS5, some things have changed

  • April 12, 2010
  • 22 replies
  • 62310 views

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

This topic has been closed for replies.

22 replies

Harbs.
Harbs.Author
Legend
April 12, 2010

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

Harbs.
Harbs.Author
Legend
April 12, 2010

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

Inspiring
May 7, 2010

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!

Harbs.
Harbs.Author
Legend
May 10, 2010

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