I’ve been making adjustments a feature in my plugin that involves creating custom hyperlinks, and attempting to use the hyperlink IDs to identify and manipulate them. When creating a new custom hyperlink the plugin stores the ID associated with the hyperlink to a json file so that it can be referenced again. This all works but i’ve hit a huge roadblock: hyperlink IDs change. From what i can tell the IDs only change when you cancel a story check out, even if nothing in the story changed. How can i work with this programmatically? i can’t identify the hyperlinks anymore if the ID in InDesign has changed from what i have stored.
in the screen shot below it can be seen that any hyperlink’s ID in the same story is changing when cancelling a story check out. In the example, “American National Standards Institute (ANSI)@18” is in the story being checked out, then cancelling the check out, and “Pressure@16” is in a separate story that is not being changed:
Apparently (read: I did not verify) when you cancel checkout InDesign discards the story and rebuilds it from the associated assignment. From the C++ side I remember there are ways to preserve an ID for such scenarios, but I did not try whether that works. Even if it does, it apparently is not used in the particular case. File a bug report and wait until is fixed. Until then:
When you preserve your IDs in that json, also use insertLabel() on the hyperlink. They should survive even when the story is rebuilt. For obvious reasons that should happen before you create the assignment, and before you bet the farm on it verify that these labels are contained in your files.
If you’re desperate about existing data, have a peek at the .icml where the old IDs should be preserved in some attribute. Build a table in that order. The newly assigned hyperlink IDs should have the same order.
I’d wonder what else is lost on such a roundtrip, e.g. when a hyperlink text destination is within your rebuilt story, what happens to references from other stories …