Skip to main content
Participating Frequently
December 6, 2011
Answered

Indesign Scripting Object Model

  • December 6, 2011
  • 1 reply
  • 11770 views

Hi,

Is there some reference documentation that provides detailed information on the Indesign object model as exposed to the scripting interface (javascript)?

I have done fair amount of scripting in Illustrator so I was looking for the Indesign equivalent of this document

http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/pdf/illustrator/scripting/illustrator_scripting_reference_javascript_cs5.pdf

I looked at this document but it seems kind of sparse (compared to illustrator)

http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/products/indesign/pdfs/InDesignCS5_ScriptingGuide_JS.pdf

Obviously they are different applications but I was kind of hoping there would be more info for Indesign scripting.

In particular I am looking for some insight on how to effectively walk or traverse the document structure of an indesign document using code.

Finding specific things by type seems out of the picture becuase after doing object reflection on all the page items in an indesign document nothing seems to have a "type" property.

In my illustrator scripts I was able to place stuff in illustrator layers, give arbitrary pageitems a name and then later go find and manipulate via script. Not as clear how to do this in an indesign context.

The one advantage of this was that in illustrator I was able to use textframes to hold variable data and read later via scripts. The document becomes the database. And I could create any number of arbitrary "variables" inside the document outside the white board. WOndering how to do this kind of stuff with indesign so I can do template driven documents that are managed by scriptings and form UI that I create.

This topic has been closed for replies.
Correct answer John Hawkinson

Is there some reference documentation that provides detailed information on the Indesign object model as exposed to the scripting interface (javascript)?

Jongware has produced a reference in CHM and HTML format from the ESTK's OMV XML, and it is invaluable:

See http://jongware.com/idjshelp.html or the exploded HTML version at http://jongware.mit.edu/idcs5js/.

In particular I am looking for some insight on how to effectively walk or traverse the document structure of an indesign document using code.

Finding specific things by type seems out of the picture becuase after doing object reflection on all the page items in an indesign document nothing seems to have a "type" property.

Typically one would iterate over the type of object you want, e.g. iterate over app.activeDocument.textFrames,

and not over .pageItems.

In my illustrator scripts I was able to place stuff in illustrator layers, give arbitrary pageitems a name and then later go find and manipulate via script. Not as clear how to do this in an indesign context.

It's not clear to me how you are stuck. You can use .itemByName() to reference an item by its name, and also the script label may be useful for that. Or, of course, you can store the items (well, references to them) in an array or object of your own.

The one advantage of this was that in illustrator I was able to use textframes to hold variable data and read later via scripts.

You can use the script label property for that.

Perhaps you could give us a much more concrete example of how you are stuck, because it's not really clear to me from your question...

1 reply

John Hawkinson
John HawkinsonCorrect answer
Inspiring
December 6, 2011

Is there some reference documentation that provides detailed information on the Indesign object model as exposed to the scripting interface (javascript)?

Jongware has produced a reference in CHM and HTML format from the ESTK's OMV XML, and it is invaluable:

See http://jongware.com/idjshelp.html or the exploded HTML version at http://jongware.mit.edu/idcs5js/.

In particular I am looking for some insight on how to effectively walk or traverse the document structure of an indesign document using code.

Finding specific things by type seems out of the picture becuase after doing object reflection on all the page items in an indesign document nothing seems to have a "type" property.

Typically one would iterate over the type of object you want, e.g. iterate over app.activeDocument.textFrames,

and not over .pageItems.

In my illustrator scripts I was able to place stuff in illustrator layers, give arbitrary pageitems a name and then later go find and manipulate via script. Not as clear how to do this in an indesign context.

It's not clear to me how you are stuck. You can use .itemByName() to reference an item by its name, and also the script label may be useful for that. Or, of course, you can store the items (well, references to them) in an array or object of your own.

The one advantage of this was that in illustrator I was able to use textframes to hold variable data and read later via scripts.

You can use the script label property for that.

Perhaps you could give us a much more concrete example of how you are stuck, because it's not really clear to me from your question...

Participating Frequently
December 6, 2011

Thanks John.

This is helpful information. To be honest I am just starting to dip my toes into scripting for indesign. I was was curious about the object model because reading the documentation for illustrator gave a me a really firm grounding on how the internals of illustrator. What hoping for the same thing for indesign.

Will look into the itemByName() function.

Also, saw in another thread that there are insert and extract methods for the label property and the ability to create custom properties. I think this will allow me to do what I want to do.

John Hawkinson
Inspiring
December 6, 2011

This is...not a common operation. InDesign does not give you an easy way to hang on to a reference to a range of text within a textframe so you can come back to it later -- because runs of characters are not objects (much less first-class objects).

I suppose you could do this with XML tags. You can apply an XML tag to a range of text (try this in the UI, first!), and see it in the Structure pane. You can then reference by the tag. Normally I would avoid XML at all costs, but it's probably the way to go here.

You could also keep track of the character offsets of the beginning and end of your substitutions. Or mark them with a character style. Those do not seem like good answers.