Author Topic: How to insert bookmarks in docgen script  (Read 285 times)

michielper

  • EA User
  • **
  • Posts: 149
  • Karma: +2/-1
    • View Profile
How to insert bookmarks in docgen script
« on: August 26, 2020, 12:20:05 am »
I am working on a (complex) VBScript to generate a (complex) report from a (complex) model.....

We have the requirement to add page-number references in certain tables. Is this possible? Can I insert some sort of reference that will then automagically be translated into a page number when the report is finalized (like apparently is being done for the Table of Contents)?

If no, I might try to use Hyperlinks instead of page numbers. There is a method docGenerator.InsertHyperlink but I don't know how to insert a BOOKMARK to refer to in the hyperlink. The documentation says

InsertHyperlink (string Name, string URL)
Notes: Inserts a hyperlink at the current location. If you use a URL with the  #BOOKMARKNAME syntax, the hyperlink will link to another part of the document.

but it is not clear to me what the refered bookmark should look like.

Thanks for any help.

Uffe

  • EA Practitioner
  • ***
  • Posts: 1775
  • Karma: +122/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: How to insert bookmarks in docgen script
« Reply #1 on: August 26, 2020, 07:42:11 am »
Hello,

I am working on a (complex) VBScript to generate a (complex) report from a (complex) model.....
A person after my own heart. :)
Quote
We have the requirement to add page-number references in certain tables. Is this possible? Can I insert some sort of reference that will then automagically be translated into a page number when the report is finalized (like apparently is being done for the Table of Contents)?
Don't think so. ToC templates are highly magical, to the point that I don't think you can actually create one in the built-in editor but must construct it in Word and then import it. The EA editor just doesn't allow you to express cross-references.

Quote
If no, I might try to use Hyperlinks instead of page numbers. There is a method docGenerator.InsertHyperlink but I don't know how to insert a BOOKMARK to refer to in the hyperlink.

I went down the BOOKMARK rabbit hole a couple of months ago, and can report that there's nothing down there. You can't create the bookmarks through the API, and while you can create them in a template, any repeated applications of the same template (you know, the whole friggin' point of using templates in the first place) breaks the whole thing since only the bookmark from the last of those applications survives to be targetted by the hyperlink.
Looks like this is another one of those functions that got included as a feature demo a loooong time ago, then never got made to actually work because nobody ended up using it.

HTH,

(Actually, I know it doesn't. It just adds to your frustration. But maybe it'll save you spending stupid amounts of time looking for a function that's implied by the documentation, but simply isn't there.)

/Uffe
My theories are always correct, just apply them to the right reality.

michielper

  • EA User
  • **
  • Posts: 149
  • Karma: +2/-1
    • View Profile
Re: How to insert bookmarks in docgen script
« Reply #2 on: August 28, 2020, 01:34:55 am »
Hello,

I am working on a (complex) VBScript to generate a (complex) report from a (complex) model.....
A person after my own heart. :)
Quote
We have the requirement to add page-number references in certain tables. Is this possible? Can I insert some sort of reference that will then automagically be translated into a page number when the report is finalized (like apparently is being done for the Table of Contents)?
Don't think so. ToC templates are highly magical, to the point that I don't think you can actually create one in the built-in editor but must construct it in Word and then import it. The EA editor just doesn't allow you to express cross-references.

Quote
If no, I might try to use Hyperlinks instead of page numbers. There is a method docGenerator.InsertHyperlink but I don't know how to insert a BOOKMARK to refer to in the hyperlink.

I went down the BOOKMARK rabbit hole a couple of months ago, and can report that there's nothing down there. You can't create the bookmarks through the API, and while you can create them in a template, any repeated applications of the same template (you know, the whole friggin' point of using templates in the first place) breaks the whole thing since only the bookmark from the last of those applications survives to be targetted by the hyperlink.
Looks like this is another one of those functions that got included as a feature demo a loooong time ago, then never got made to actually work because nobody ended up using it.

HTH,

(Actually, I know it doesn't. It just adds to your frustration. But maybe it'll save you spending stupid amounts of time looking for a function that's implied by the documentation, but simply isn't there.)

/Uffe

Allright, thanks for sharing these insights. It looks like indeed I wont be able to accomplish exactly what I want.
However, in my case, there are actually some one-time templates because I use them for certain section headers in the document that occur only once. In some of these cases, it might be useful to include a hyperlink reference to these one-time templates.
 So, how do I create and reference a bookmark in a template then?

Regards, Michiel

Uffe

  • EA Practitioner
  • ***
  • Posts: 1775
  • Karma: +122/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: How to insert bookmarks in docgen script
« Reply #3 on: August 28, 2020, 02:32:02 am »
Allright, thanks for sharing these insights. It looks like indeed I wont be able to accomplish exactly what I want.
However, in my case, there are actually some one-time templates because I use them for certain section headers in the document that occur only once. In some of these cases, it might be useful to include a hyperlink reference to these one-time templates.
 So, how do I create and reference a bookmark in a template then?

Creating a bookmark is easy. In the template editor, simply go Edit -- Edit -- Insert -- Bookmark.
This doesn't insert a bookmark as such, but it opens a dialog where you can choose to do so.
This dialog is also the only way to locate and delete bookmarks once you've created them. They don't show up if you select Edit -- File -- View -- Hidden Text or anything.

Referencing is just a matter of calling DocumentGenerator.InsertHyperlink() with the link text and the bookmark name prefixed with a # character.

I'm pretty sure. Last time around I gave up in disgust so I haven't used this in any production scripts.


/Uffe
My theories are always correct, just apply them to the right reality.

michielper

  • EA User
  • **
  • Posts: 149
  • Karma: +2/-1
    • View Profile
Re: How to insert bookmarks in docgen script
« Reply #4 on: August 28, 2020, 07:38:16 pm »
Thanks again Uffe! I will do some experimentation.

Another, though somewhat elaborate, way to accomplish something useful in this area might be to have an EA script create a “concordance” file that you can then use to let your word processor generate an index. This of course might be impossible to automate completely but can be acceptable if new versions of documents are not required very often.