• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Advocate ,
Aug 13, 2011 Aug 13, 2011

Copy link to clipboard

Copied

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.

TOPICS
Scripting

Views

795

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 28, 2011 Sep 28, 2011

Copy link to clipboard

Copied

LATEST

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;    

    }

    return;

}

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines