1 Reply Latest reply on Sep 28, 2011 3:01 PM by OliverJohn

    How can I get the Doc object from any other object?

    Michael Müller-Hillebrand Level 4

      Dear colleagues,


      in FrameScript it is dead-simple to get to the document part of any object, just add .Doc to the variable.


      How can I achieve the same with ExtendScript? I amtired of passing the document object next to AFrames or Pgfs along into subroutines, because those objects already contain the information about their document. But how do I access this?


      Thanks for pointers,


      - Michael



      PS: Almost the same is true for the page an object lives on. With FrameScript we use .Page, with ExtendScript you have to move up the object tree until you reach the UnanchoredFrame.PageFramePage…


      PPS: It would be great to see some convenience properties like .Doc and .Page implemented natively.

        • 1. Re: How can I get the Doc object from any other object?
          OliverJohn Level 2

          I'll preface this response by admitting this far from an elegant solution, but I did write a function addressing this question, mostly as an exercise.


          If passed an object with an InTextFrame property (Pgf, AFrame, Cell, Fn) that resides in an open document, the function will return the Doc object. Otherwise, it returns undefined.


          function getParentDoc(testObj) {

              //Get object for current page

              try { var curPage = testObj.InTextFrame.FrameParent.PageFramePage; }

              catch(er) {return;}

              //Step backwards to first page in document

              var prevPage = curPage.PagePrev;

              while (prevPage.ObjectValid())


                  curPage = prevPage;

                  prevPage = prevPage.PagePrev;


              //Compare with first pages of open documents

              var testDoc = app.FirstOpenDoc;

              while (testDoc.ObjectValid())


                  if (curPage.id==testDoc.FirstBodyPageInDoc.id) return testDoc;

                  testDoc = testDoc.NextOpenDocInSession;    






          To your PPS: Rather than seeing the native framework grow bloated to address additional features, I would love to see Adobe and other developers publish libraries of useful functions and class extensions.