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

With CS5, some things have changed

  • April 12, 2010
  • 22 replies
  • 62285 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

Inspiring
November 26, 2016

My admittedly old CD for InDesign 5 (Windows) is no longer readable. Where can I find a guide to scripting?

Inspiring
November 26, 2016

Problem solved!

Known Participant
September 27, 2011

Hi everyone, I am running a VB script that I wrote for InDesign CS2 on CS5. The code below does not seem to work. Does CS5 understand Changecase? If someone knows or could point me to the CS5 VB script reference I would greatly appreciate it. I can't seem to locate any information.

.Paragraphs(2).Changecase (idSentencecase)

Thank you for helping!

Mike

Robert at ID-Tasker
Legend
September 27, 2011

Hi Mike,

.Paragraphs(2).Changecase (idSentencecase)

Try to use numbers:

Const idSentencecase = 1667461987 (&H63637363)

    Member of InDesign.idChangecaseMode

    Makes the first letter of each sentence uppercase.

   .Paragraphs(2).Changecase (1667461987)

Are you sure there is 2nd Paragraph ?

What error do you have ?

Or what is the type of the Text object you try to modify ?

robin

www.adobescripts.co.uk

Known Participant
September 28, 2011

Using the number worked perfectly. Thank you!!

Participating Frequently
June 7, 2011

With a script that worked OK in CS4 I now find that when I set the strokewidth of a frame to 0 the result is a frame having a stroke of 1 pt, using the default TextFrame Object style. In both cases I used the same template file to start with so the Object Style is somehow changed or is now applied and not inprevious versions ? Do I need to set the ObjectStyle to None on all frames in CS5 to avoid this ?

Participating Frequently
June 7, 2011

Just found out myself that just after setting frame.strokewidth = 0 the value for frame.strokewidth is actually 1 pt; if I set strokewidth = 0.000001 then the value returned is actually 0.000001 pt so will show as 0 in InDesign dialogs.
So now my question is: how to set strokewidth to zero in InDesign CS5 ?

May 4, 2011

Apologies for cross posting this to both mailing list and forums, I'm not sure what most people are using.

Just starting to look at moving the company from CS3 to CS5/5.5 and updating the scripts has been, well, interesting.  The inability to directly refer to page items via their Label has been quite a challenge as EVERYTHING we do names frames and subsequently refers to them by that name.

One thing that has me stuck is why the following doesn't throw an error in a try block if the frame doesn't exist.

set myFrame to item 1 of all page items whose label is "kim"

I simply end up with an undefined variable. I would have thought if it didn't exist and myFrame was undefined an error should be returned.

Am I missing something here or is this expected behaviour?

I've just found another issue regarding restoration of styles to a frame. In CS3 we used to simply get the parent story properties from the frame, place the new text and then reapply the properties to restore the style. In CS5 this breaks as it simply applies the default paragraph style despite the properties holding all the individual style elements. I'm thinking this will necessitate applying individual properties (font, leading, tracking, kerning, etc etc) and that's gonna be horrible. If someone has a workaround for this I would appreciate it.

It's been a long time since I wrote these scripts and there's a LOT of work in updating them to follow the new syntax - this is going to be a far more substantial task than I was expecting.

cheers

'k

John Hawkinson
Inspiring
May 4, 2011
It's been a long time since I wrote these scripts and there's a LOT of work in updating them to follow the new syntax - this is going to be a far more substantial task than I was expecting.

Perhaps you should consider using:

--Set to 5.0 scripting object model
set version of script preferences to 5.0

until such time as you need to make serious use of CS5 features?

One thing that has me stuck is why the following doesn't throw an error in a try block if the frame doesn't exist.

set myFrame to item 1 of all page items whose label is "kim"

I simply end up with an undefined variable. I would have thought if it didn't exist and myFrame was undefined an error should be returned.

Am I missing something here or is this expected behaviour?

It is indeed expected!

A "whose" filter in AppleScript is permitted to return a null list. Errors are only supposed to be thrown in fairly serious errors. Depending on how you try to use the myFrame it might generate an error later though...

May 4, 2011

Well it's certainly returning an error when used later

And there's the rub, in the CS3 version there was no problem simply checking to see if the frame existed but with the variable assignment failing without error the existence check naturally fails as well. I have coded a (fairly clunky) workaround which I think will be reliable but I still think returning an error when trying to assign a non-existent object to a variable makes sense.

With regards using the v5 Scripting, I figure I may as well just bite the bullet and get it done. We're probably a few months away from upgrading (and I'm the one who decides so it can be further postponed) so it's just a matter of getting it all done.

I like fiddling around but when I haven't looked at the scripts in probably 5 years it can take a while to get back into the swing of things

Inspiring
April 29, 2011

Just found another really unfortunate change in CS5. It is no longer safe to issue:

myTextFrame.lines[-1].baseline

even when the text frame is known to contain at least one line because if that line contains a partial table that is not completely set (i.e., the story goes overset before the end of the table) you'll get "Invalid request in the current state".

Possibly worse, if the table is completely set, rather than get the bottom coordinate of the part of the table in the text frame, you instead get the baseline of the actual bottom of the last row of the table no matter which text frame it might actually be in on whichever page.

A really sad state of affairs that wipes out my script that does vertical justification of tables.

Dave

Inspiring
April 18, 2011

So far, I've slept through all the CS5 activity because our customers have been using CS3 and CS4, but now, some of them are putting their toes into the CS5 water and so I'm finally paying attention to what is now the release before last (ah well).

According to the CS5 OMV, Text.contents returns either a String or a SpecialCharacters enumerator. But this code is failing on me:

var txtSample = oSetText.contents.replace(/\t/g,"[Tab]");

because contents is returning an array.
Here's what the JS Console has to say:
oSetText.contents
Result: Linda [stroke survivor]
“If you don’t have a proper wheelchair, that is when you really feel that you are disabled. But if you have a proper wheelchair, which meets your needs and suits you, you can forget about your disability.”
Faustina [person with paraplegia]
oSetText.contents.constructor.name
Result: Array
oSetText.contents.length
Result: 1
oSetText
Result: [object Text]
Anbody else seen this? Or am I suffering from a third-party plug-in induced weirdness?
Dave

Inspiring
April 18, 2011

I think I see the cause. I typed:

This is a test.

into a text frame, and selected it.

app.selection[0]

Result: [object Paragraph]

app.selection[0].texts[0]

Result: [object Text]

app.selection[0].texts[0].contents

Result: This is some text.

app.selection[0].texts[0].contents.constructor.name

Result: String

app.selection[0].parentStory.characters.itemByRange(0,-1).texts[0]

Result: [object Text]

app.selection[0].parentStory.characters.itemByRange(0,-1).texts[0].contents

Result: This is some text.

app.selection[0].parentStory.characters.itemByRange(0,-1).texts[0].contents.constructor.name

Result: Array

It appears that using itemByRange across a range of text is at the root of the issue here because this second construction is akin to what I had done in the other script.
To be blunt, this looks like a bug to me, but as long as it is consistent, I can work with it.
Dave
Inspiring
April 19, 2011

The solution (which works in at least CS4 and CS5) is to use getElements():

app.selection[0].parentStory.characters.itemByRange(0,-1).texts[0].getElements()[0].contents.constructor.name

String

However, in CS4 and earlier, the use of getElements here was not necessary.

Dave


Participant
March 11, 2011

A couple of other things I've noticed:

1. The Book.exportFile() parameters have changed (which bring them more in line with Document.exportFile()), so:

CS4: myBook.exportFile(myPdfFile, false)

CS5: myBook.exportFile(ExportFormat.PDF_TYPE, myPdfFile)

2. The regular expression engine seems to have been changed slightly, in CS5 you now have to escape pipes.

Consider the expression:

$.writeln('test'.replace(/|/g, '|'));

CS4: 'test'

CS5: '|t|e|s|t'

You have to escape the pipe like this:

$.writeln('test'.replace(/\|/g, '|'));

Harbs.
Harbs.Author
Legend
March 11, 2011

Hi Ben,

Nice to see you here!

Yes there are definitely things that changed with the RegExp engine. One important thing to know is that for regex that will be used more than once it's important to create a RegExp object and invoke it by referencing it rather than using a regex literal which the engine has to reconstruct each tme it's used. This makes a huge difference in performance in CS5...

Harbs

Known Participant
September 28, 2011

Can anyone point me to a CS5 VB script reference? Having trouble locating one.

Thank you,

Mike

March 8, 2011

In case anyone's interested: In the VB object model (not sure of anything else) the idTextWrapTypes was changed to idTextWrapModes.

Not sure why, but there 'tis.

Inspiring
March 4, 2011

Hi all,

we just tracked down a bug to the E4X implementation in ExtendScript. Fixed in CS5, but unfortunately that project is still CS4.

First, be assured that below syntax is no typo - for details see the XML section in the JavaScript Tools Guide. The code implements different approaches to initialize a simple XML object (the ExtendScript brew, not InDesign's XMLElement) with a single element and text content. The curly brackets within the embedded XML literal are a way to pass on JavaScript expressions.

The only problem here - some kind of conversion is taking place under the hood. Speaking in InDesign character codes, the paragraph end character (13) is silently converted into a forced line break (10). Not good if this XML is later returned into InDesign ...

Dirk

( function () {   var aCRbLFc = "a\rb\nc";   $.writeln(aCRbLFc.charCodeAt(1),"/",aCRbLFc.charCodeAt(3));   // => 13,10   // first attempt / redundant XML wrapping.   var xml = new XML(<tag>{aCRbLFc}</tag>);   var hmm = xml.child(0).toString();   $.writeln(hmm.charCodeAt(1),"/",hmm.charCodeAt(3));   // => 10,10   // second attempt / straight XML literal   var xml = <tag>{aCRbLFc}</tag>;   var hmm = xml.child(0).toString();   $.writeln(hmm.charCodeAt(1),"/",hmm.charCodeAt(3));   // => 10,10   // inconsequent, but works:   var xml = new XML(<tag/>);   xml.appendChild(aCRbLFc);   var hmm = xml.child(0).toString();   $.writeln(hmm.charCodeAt(1),"/",hmm.charCodeAt(3));   // => 13,10 } )();

Edit: formatting attempt

Known Participant
January 29, 2011

I noticed today the the Object Model for CS4 has xmlItems.ItemByName, but the Object Model for CS5 does not. I'm trying to work out how to reference an XML Element by name in CS5. xmlItems.item("myElementName") doesn't work. Any ideas?

Harbs.
Harbs.Author
Legend
January 29, 2011

Interesting. How did it work in CS4?

XMLElements don't have names or labels...

If you are trying to get an element based on its tag, you can check each element's markupTag.

Harbs

grefel
Community Expert
Community Expert
January 30, 2011

Interesting finding. I was sure that Adobe had'nt changed anything regarding to XML in CS5. As far as I can see/test your observation is correct.

I would suggest to use the class XMLElement instead of working with the superclass XMLItem.

Given this structure:

<root>

     <child/>

</root>

I would use in CS3/4/5:

app.activeDocument.xmlElements[0].xmlElements.itemByName("child");

Working, but strange:

app.activeDocument.xmlItems[0].xmlElements.itemByName("child");

regards,

gregor