4 Replies Latest reply on May 20, 2009 10:08 AM by Harbs.

    Under which circumstances might the id property change?

    Andreas Jansson Level 2

      I've always been cautious using the id property after reading that it could, under certain circumstances, be changed by InDesign and then not identifying the same object or any object at all. One should not use the id to keep track of the indesign objects on a page by storing them in a database and then expect to find the same objects the next day - that's what I remeber reading, even if I can't find it right now.

       

      Exactly what were those circumstances - when might the id property change? Is it when opening the document, or while working with it, doing some dramatic changes to an object? I've changed contents between text and graphics and unassigned on a frame, but this did not result in the id property changing.

       

      -- Andreas

        • 1. Re: Under which circumstances might the id property change?
          Dave Saunders Level 4

          I have relied on id not changing in many scripts.

           

          The one case I know of that can be confusing is if you thread a text frame to the start of story then that changes the story object and so it gets a new id.

           

          Dave

          • 2. Re: Under which circumstances might the id property change?
            Andreas Jansson Level 2

            I'm not exactly sure on what threading a text frame to the start of story means, but that's the id of the story that changes then, right? Not the text frame?

             

            When I think of it, I do also rely on ids of text- and graphic frames not changing, at least not while working with them, and just performing simple actions such as moving and changing contents in them.

             

            But I've always had this bad feeling about them, ever since reading that they could change and should not be stored for later use.

             

            -- Andreas

            • 3. Re: Under which circumstances might the id property change?
              Dave Saunders Level 4

              Having never read that, I have avoided the bad feeling in question.

               

              I saw somewhere recently that the ids of xmlElements can change but I've never used ids when working with those objects.

               

              And yes, you're right, the text frame id wouldn't change.

               

              The situation I was referring to would come up if you did this:

               

              myStory.textContainers[0].previousTextFrame = someTextFrame;

               

              The need to do that doesn't come up very often, but this would result in myStory becoming an invalid reference and the story would have a new id. Thinks: I should try this before sounding so authoritative.

               

              OK, I appear to be right as this script demonstrates:

               

              myDoc = app.documents.add();
              var myTF = myDoc.pages[0].textFrames.add({geometricBounds:myDoc.pages[0].bounds});
              var myStory = myTF.parentStory;
              myStory.contents = String(myStory.id);
              var myNewTF = myDoc.pages[0].textFrames.add();
              myStory.textContainers[0].previousTextFrame = myNewTF;
              alert(myStory.contents);

               

              Run it and you'll get an error instead of the alert because the object no longer exists.

               

              Dave

              1 person found this helpful
              • 4. Re: Under which circumstances might the id property change?
                Harbs. Level 6

                IDs are the most stable property in InDesign. They are based on the 

                UIDs on the C++ level which is how InDesign keeps track of objects 

                internally.

                 

                What Dave meant is that if you are relying on IDs, you need to be sure 

                that the object remains the same one. When you thread together two 

                text frames, you are merging two stories together. The first story is 

                the "real" one. There is a very real difference whether you thread 

                them together by stating mySecondFrame.previous textFrame = 

                myFirstFrame or myFirstFrame.nextTextFrame = mySecondFrame.

                 

                Another "gotcha" is while overriding a master page item. The 

                overridden item is a NEW item with a new ID -- different than the 

                master page one.

                 

                Harbs

                http://www.in-tools.com

                1 person found this helpful