🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #1999

(JS) Find Page of Object

#1999
From: Dave_Saunders
Date: Mon, 12 Jan 2009 21:08
28 lines
1838 bytes
While preparing a presentation I'm going to be giving in a couple of months, I took a good hard look at my findPage(theObj) function and I think that this is as good as it gets:

function findPage(theObj) { 
  if (theObj.hasOwnProperty("baseline")) { 
    theObj = theObj.parentTextFrames[0]; 
  } 
while (theObj != null && theObj.constructor != Page) { 
    var whatIsIt = theObj.constructor; 
    switch (whatIsIt) { 
      case null : return null; 
      case Character : theObj = theObj.parentTextFrames[0]; break; 
      case Cell : theObj = theObj.insertionPoints[0].parentTextFrames[0]; break; 
      case Application : return null; 
    } 
    if (theObj == null) return null; 
    theObj = theObj.parent; 
  } 
  return theObj 
} // end findPage 


The previous versions posted in various threads here reflected various degrees of needless caution about what might happen, for example if the object were anchored to text in a cell in an overset table. The above returns null in that case with no need for try/catch.

Notice the use of objects rather than their names. Works! This is similar to the instanceof construction but it's easier to test the negative.

If anyone can knock a hole in the above script, I'd be very interested in hearing about it.

Dave
Technical Details
Message-ID: <59b77ee3.-1@webcrossing.la2eafNXanI>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.glorb.com!newshub.sdsu.edu!webcrossing

Show Full Headers
Complete Article Headers
X-Google-Thread: f939a,54700b22cee37b94,start
X-Google-Attributes: gidf939a,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: Dave_Saunders@adobeforums.com
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.glorb.com!newshub.sdsu.edu!webcrossing
Newsgroups: adobe.scripting.indesign
Subject: (JS) Find Page of Object
Message-ID: <59b77ee3.-1@webcrossing.la2eafNXanI>
Date: Mon, 12 Jan 2009 13:08:27 -0800
Lines: 33
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit