9 Replies Latest reply on Aug 4, 2017 6:30 AM by tobiask43046735

    How to assign constant ids to everything?

    tobiask43046735 Level 1

      I wrote a small script to automatically export to IDML and extract that, so that my version control system (git) manages a bunch of xml files instead of binary garbage. The problem is that InDesign keeps changing ids of elements, e.g. one time there'll be a story_uaf1.xml containing a

      <story Self="uaf1" ...>
      

      tag, the next time it might be named story_u1fc.xml instead. The same goes for cross-refs and such. That makes the diff (changelog) of git rather tedious to read since the actual changes are buried between meaningless meta-changes. Is there any way to assign fixed ids instead?

        • 1. Re: How to assign constant ids to everything?
          Ben-Berkadia Level 1

          I would assume you have to build out your script further to actually create the series of XML files found in an IDML (package of files) and then also ensure that those XML files are packaged into IDML correctly (to be readable by InDesign, etc.)  if you want to maintain ID names for version control.

          • 2. Re: How to assign constant ids to everything?
            Laubender Adobe Community Professional & MVP

            Hi Tobias,

            to do constant IDs to objects one can try to insert labels with unique strings.

             

            But that would also require some event listening mechanisms that could detect actions by a user like copy/paste or duplicating items and assigning new unique strings to the copied or duplicated items. You'd need that also if duplicates of documents are created or pages are moved or duplicated to other documents. Or snippets are placed or assets are placed from an InDesign library file.

             

            See into methods:

            insertLabel( "keystring" , "valuestring" )

            extractLabel( "keystring" )

             

            You'll find the inserted labels in IDML easily. Experiment with IDMS first, then proceed with IDML.

            Opening an IDML file with inserted labels would require to either preprocess the IDML file before opening as document or doing that right after opening to change the labels in a constant way to get unique IDs on basis of "valuestring" of an inserted label of an object.

             

            insertLabel() and extractLabel() is available for a lot of objects.
            Also to Story. But not to text like paragraphs, words, characters and insertionPoints.

             

            But all that provokes the question:

            What makes an object unique?

             

            If you open an IDML with InDesign, if you place an IDMS with InDesign, if you place an asset from an InDesign library or from CC Library the opened IDML or the placed IDMS or the placed asset is build from scratch!

             

            After rules that app preferences or document preferences will govern.

            So it could be that a snippet is interpreted in different ways depending on other settings. It's the same with IDML. If you open an IDML with preferences set to X the results could be different from opening the IDML with pereferences Y. Or if you are using different versions of InDesign the results could be different.

             

            Don't know if any version control system could be adapted to that…

             

            Regards,

            Uwe

            • 3. Re: How to assign constant ids to everything?
              Dirk Becker Level 4

              There is a call "IDataBase::PlacementNewUID" in the C++ API  - create a new persistent object with the desired UID specified. This call has been in place at least since Version 4 / CS2 - the earliest SDKs on this Mac. I always thought it would get used for exactly that purpose - preserve incoming IDs where possible, but I now realize that was wishful thinking. The different ways to create an object usually don't let you specify the ID, and it is nowhere used in example code.

               

              You could establish a convention for more long-term identification of any object and pre checkin fix the IDML, attempt to restore the previous IDs. Even if you get the renumbering straight, I fear that attempt would fail in many regards - a style was renamed, is it the same? It was moved into a different group. Still the same, or a duplicate? Two text frames were chained, removing one of their stories. An image was relinked meaning internal replace. Same URL or different? And so forth. Probably vendors of editorial systems have already run into the same problem but buried their solution in their proprietary backend. Assume you get it going, now consider collisions on git pull requests ;-)

               

              Have fun,

              Dirk

              • 4. Re: How to assign constant ids to everything?
                Marc Autret Level 4

                Hi Tobias,

                 

                Not sure my idea is relevant, but another approach would be to insert an intermediate routine purposed to normalize your IDML data before storing and diff. My guess is, Self attributes of the form "uHHH…" are arbitrary hex IDs, subject they keep consistent over the whole IDML stream—that is, if the same ID occurs multiple times, you must of course preserve the identity of those multiple instances.

                 

                So, you might have the option to define a 1-to-1 correspondence between original arbitrary IDs and the regular sequence "u1", "u2"... "ua" ... "uf" ... "u10" etc. This way the resulting xml would be the same as long as the DOM objects are the same modulo their arbitrary ID.

                 

                Can IDML experts confirm this? Does it make sense?

                 

                @+

                Marc

                • 5. Re: How to assign constant ids to everything?
                  tobiask43046735 Level 1

                  Hi Uwe,

                  Laubender  wrote


                  After rules that app preferences or document preferences will govern.

                  So it could be that a snippet is interpreted in different ways depending on other settings. It's the same with IDML. If you open an IDML with preferences set to X the results could be different from opening the IDML with pereferences Y. Or if you are using different versions of InDesign the results could be different.

                  I skimmed the IDML specification, apparently for that very reason there are some defaults which IDML import will apply unless explicitly overridden. Though that won't help if the IDML file uses a feature from a too new InDesign version...

                   

                  Your suggestion of using labels sounds like a good idea to get started, I'll keep that in mind, thanks.

                   

                  Cheers,

                  Tobias

                  • 6. Re: How to assign constant ids to everything?
                    tobiask43046735 Level 1

                    Dirk Becker  wrote

                     

                    You could establish a convention for more long-term identification of any object and pre checkin fix the IDML, attempt to restore the previous IDs. Even if you get the renumbering straight, I fear that attempt would fail in many regards - a style was renamed, is it the same? It was moved into a different group. Still the same, or a duplicate? Two text frames were chained, removing one of their stories. An image was relinked meaning internal replace. Same URL or different? And so forth. Probably vendors of editorial systems have already run into the same problem but buried their solution in their proprietary backend. Assume you get it going, now consider collisions on git pull requests ;-)

                    Hi Dirk,

                     

                    that's about the worst-case scenario I assumed... Tracking all the uids, replacing them with some pseudo-constant placeholders etc. But on the other hand the best chance to get actual merges without conflicts... Oh well, this is unfortunately beyond my capacity at the moment.

                     

                    Cheers,

                    Tobias

                    • 7. Re: How to assign constant ids to everything?
                      tobiask43046735 Level 1

                      Marc Autret  wrote

                       

                      Hi Tobias,

                       

                      Not sure my idea is relevant, but another approach would be to insert an intermediate routine purposed to normalize your IDML data before storing and diff. My guess is, Self attributes of the form "uHHH…" are arbitrary hex IDs, subject they keep consistent over the whole IDML stream—that is, if the same ID occurs multiple times, you must of course preserve the identity of those multiple instances.

                       

                      So, you might have the option to define a 1-to-1 correspondence between original arbitrary IDs and the regular sequence "u1", "u2"... "ua" ... "uf" ... "u10" etc. This way the resulting xml would be the same as long as the DOM objects are the same modulo their arbitrary ID.

                       

                      Can IDML experts confirm this? Does it make sense?

                       

                      @+

                      Marc

                      Hi Marc,

                       

                      normalization is precisely what I would like to achieve, the question is whether I can force InDesign to keep that instead of re-assigning random uids. I skimmed the IDML specification, since I seemed to remember having read something about manually assigned uids to be maintained, but I cannot find it again. I guess I have to experiment a bit. But even if I manage to get constant ids for stories, at the very least refreshed cross-references seem to get re-assigned every time...

                       

                      Cheers,

                      Tobias

                       

                      PS: nice work you do with your scripts

                      • 8. Re: How to assign constant ids to everything?
                        Dirk Becker Level 4

                        In the meantime I've had an idea:

                         

                        Let's assume (I have not verified that) that the IDs  stay the same when you do IDML export from the same .indd file.

                        When you now re-create a new.indd instance from IDML, the first step could be an new.idml export that should be roughly equivalent to old.idml, except for the remapped IDs (and minor version specific changes). The good thing for that is it allows you to produce a mapping from old IDs to new IDs that you can later use to re-map IDs from modified versions of the new .indd - in other words you take away the randomness.

                         

                        If only I hadn't already enough pet projects ;-)

                        • 9. Re: How to assign constant ids to everything?
                          tobiask43046735 Level 1

                          I found what I meant about fixing ids:

                           

                          8.2.3 Reset Component Name on Import

                          When an IDML package is opened by InDesign, user-defined component names will be saved in the document so they can be used when the document is exported (that is, they are preserved for round-trip).

                          Default names are not saved with the document because the object created during import may have a different UID. A new default name is generated when the document is exported.

                          And directly followed by the hint at using the IDMLComponentName property to modify that.