Copy link to clipboard
Copied
Hi,
I have several objects with the same name all on the same layer but on different pages.
To get to the item without iterating I came up with this long line of code
curDoc.layers.itemByName("Ebene 1").pageItems.everyItem().parentPage[0].pageItems.itemByName("A").contents
I would modify the parentPage index to get to the page that I need.
I wonder, if there is a better way than that. As stated above I prefer not to iterate over layer pageItems
Thanks for any help
Stefan
Hi Stefan,
don't know if this is news to you, but you might know two things:
First:
pageItems.itemByName("Name")
will only fetch the "first" item with that particular name.
Even if ther are two or more items with the same name.
Second:
doc.layers.itemByName("Ebene 1").pageItems
will only fetch page items on document spreads.
Not the ones on master spreads.
FWIW: You could work around the first issue if instead of the named items you have labeled items.
Items where property label wa
...Copy link to clipboard
Copied
If you don't want to iterate, I'd recommend just renaming the layer items. Alternative is you could iterate through allPageItems on a given page and matching to itemLayer.name. Why don't you want to iterate? You could also set up your own hash object to each item by page number and call that when desired, or hash the item IDs.
Copy link to clipboard
Copied
Hi Stefan,
don't know if this is news to you, but you might know two things:
First:
pageItems.itemByName("Name")
will only fetch the "first" item with that particular name.
Even if ther are two or more items with the same name.
Second:
doc.layers.itemByName("Ebene 1").pageItems
will only fetch page items on document spreads.
Not the ones on master spreads.
FWIW: You could work around the first issue if instead of the named items you have labeled items.
Items where property label was used instead of name.
Just some code to illustrate this:
var labelValue = "A";
var layerName = "Ebene 1";
var defaultVersion = app.scriptPreferences.version;
// Set the version to CS4:
app.scriptPreferences.version = "6.0";
// Get every labeled item on the layer ( document spreads only, NOT master spreads ) with a distinct label:
var allRecordedItemsArray =
app.documents[0].layers.itemByName( layerName ).pageItems.item( labelValue ).getElements();
// IMPORTANT: Reset the version to the default one:
app.scriptPreferences.version = defaultVersion;
// Loop the array to do something:
for( var n=0; n<allRecordedItemsArray.length; n++ )
{
/*
Do something with the found elements.
*/
};
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Thank you Uwe,
I was not really aware of you First and Second point. Very valuable info.
I guess I cannot get around iteration in this case
Thanks Stefan