Skip to main content
frameexpert
Community Expert
Community Expert
June 20, 2018
Question

Assign an ID to an Element

  • June 20, 2018
  • 2 replies
  • 2339 views

When I right + click on an element, I can choose Assign ID to Element. Is there an ExtendScript function or method for doing this? Thanks.

Alternatively, is there a solid JavaScript algorithm for generating an unique value? -Rick

This topic has been closed for replies.

2 replies

4everJang
Legend
June 21, 2018

No need for all kinds of code, Rick. Every object in FrameMaker has a unique ID. When you have the element object, you can read that unique ID from its Unique property. Note, however, that these are numbers. To make these valid IDs in XML you need to prepend them with a character, as IDs cannot start with a digit.

I have been using this for as long as ExtendScript exists and never found a duplicate ID.

Ian Proudfoot
Legend
June 21, 2018

Agreed Jang, which is what my answer (post 4) stated.

- Ian

4everJang
Legend
June 21, 2018

I overlooked that in the thread, just saw the XPath mentions and thought that is absolute overkill. :-)

Ian Proudfoot
Legend
June 20, 2018

ExtendScript supports XPath through the E4X extension. So you could use the XPath generate-id().

I believe that the FrameMaker Assign ID to Element command was originally part of the DITA add-in, so maybe it's possible to access it that way?

Ian Proudfoot
Legend
June 20, 2018

But of course there isn't a direct correlation between the FrameMaker object model and the E4X model...

frameexpert
Community Expert
Community Expert
June 20, 2018

Hi Ian,

It looks like ExtendScript's xpath method returns an XML object, so I don't think I can use an xpath function to return a string value. Thanks for the reply.

Rick

www.frameexpert.com