🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: adobe.scripting.indesign
4 messages
4 total messages Started by Rick_Quatro Wed, 21 Jan 2009 14:20
[CS3 JS] Getting a page item by its script label
#1882
Author: Rick_Quatro
Date: Wed, 21 Jan 2009 14:20
15 lines
948 bytes
I have a text frame on a master page with its script label set. In my script, I am trying to get a reference to the text frame with this:



var doc = app.activeDocument; 
var spread = doc.masterSpreads[0]; 
var tabFrame = spread.allPageItems.item("TabLeft");



I get the error "spread.allPageItems.item is not a function"

Any help will be appreciated. Thanks.

Rick
Re: [CS3 JS] Getting a page item by its script label
#1883
Author: Peter Kahrel
Date: Wed, 21 Jan 2009 14:24
8 lines
755 bytes
allPageItems returns an array. What you need is probably: 

      var tabFrame = spread.pageItems.item("TabLeft")




Peter
Re: [CS3 JS] Getting a page item by its script label
#1896
Author: Olav_Kvern
Date: Wed, 21 Jan 2009 18:16
9 lines
1462 bytes
Hi Rick,

spread.allPageItems returns a flattened array of all of the page items in the spread, at any level of the hierarchy (i.e., inside groups and other page items). Is that what you want? Sadly, allPageItems does not benefit from the special case where we use the label as a name, so you'll have to iterate if that's what you want.

As Peter says (thanks, Peter!), spread.pageItems.item("label") gives you all of the page items whose label matches the string, but it does so in sort of a weird way--you'll always get a page item object. If no page items match, you get an invalid page item; if one matched, you get a single page item, and if multiple page items matched, you get a page item object that actually contains multiple page items. It can take a little testing to figure out exactly what it is that was returned.

Thanks,

Ole
Re: [CS3 JS] Getting a page item by its script label
#1948
Author: Rick_Quatro
Date: Wed, 21 Jan 2009 18:53
15 lines
1104 bytes
OK, that explains the odd behavior I was seeing. I decided to use the code below. While not as elegant, it works!



var doc = app.activeDocument;

var spread = doc.masterSpreads[0]; 
var oPageItems = spread.allPageItems; 
for (var i = 0; i < oPageItems.length; i+=1) {      if (oPageItems[i].label.match(/Tab(Right|Left)/)) {          // Do something here.      }  }



Thanks for the generous help.

Rick
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads