Skip navigation
Currently Being Moderated

Get page of current XML element?

May 18, 2012 8:35 AM

Tags: #script #javascript #xml #indesign_cs5.5 #scripting

Hello all,

 

I am using CS5.5 and have a script (I'm using Javascript) that is placing XML elements into a text frame that is linked and spans several pages. What I'm trying to do is find out what the current page is where the current element is being inserted. Say I start on page, 10. Once the content gets to page 11, I'm want to know that I'm on page 11 with those elements as certain ones are being placed into a frame (not inline) and I want that frame to be placed on the proper page.

 

I've tried a lot of different things, and seem very close, but can't quite get it. Is there a way to tell what page an XML element is being inserted on?

 

Any advice/help is greatly appreciated.

 

Thanks.

 
Replies
  • Currently Being Moderated
    May 18, 2012 9:12 AM   in reply to islander1970

    XML Elements are not associated with a particular page, e.g. there can be elements without layout, or the root element cover all 3000 pages. For XML Elements holding text you can ask any insertion point, such as the first and the last for their parent text frames. The parent text frames property of an insertion point usually has only one entry, only the insertion points at the crossing of chained frames live in two frames.

     

    Dirk

     
    |
    Mark as:
  • Currently Being Moderated
    May 19, 2012 2:48 AM   in reply to islander1970

    You have to get the insertion points from the XMLElement. The insertion point leads to the frame and that to the page.

     

    ( function () {

        var rootXE = app.activeDocument.xmlElements.item(0);

        var articleXE = rootXE.xmlElements.item(0);

        var storyXE = articleXE.xmlElements.item(0);

        var yourXE = storyXE.xmlElements.item(0);

        var startIP = yourXE.insertionPoints.firstItem();

        var endIP = yourXE.insertionPoints.lastItem();

        var endTF = endIP.parentTextFrames[0];

        var endPage = endTF.parentPage;

        $.writeln("yourXE ends on page "+endTF.parentPage.name);

    } ) ();

     
    |
    Mark as:
  • Currently Being Moderated
    May 21, 2012 11:43 AM   in reply to islander1970

    If any text (such as your insertion point) is in overset rather than in a text container (such as a text frame) then you don't have a parent text frame. Instead of testing for that condition (parentTextFrames array has length of 0), you may also check the parent story, e.g. yourIP.parentStory.overflows.

     

    Dependent from your template / document InDesign also has a feature that may automatically add pages. If I remember that correctly, it is only triggered during composition. You would then force it with yourIP.parentStory.recompose().

     

    Dirk

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (1)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points