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

Items with same name on several pages on a specific layer

Explorer ,
Dec 08, 2020 Dec 08, 2020

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

TOPICS
Scripting

Views

199

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

correct answers 1 Correct answer

Community Expert , Dec 09, 2020 Dec 09, 2020

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

...

Votes

Translate

Translate
Community Expert ,
Dec 08, 2020 Dec 08, 2020

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. 

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
Community Expert ,
Dec 09, 2020 Dec 09, 2020

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 )

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
Explorer ,
Dec 16, 2020 Dec 16, 2020

Copy link to clipboard

Copied

LATEST

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

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