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

Select item from item name on page

Explorer ,
Jul 23, 2020 Jul 23, 2020

Copy link to clipboard

Copied

So I have a page, that has 1 layer containing 2 items:

-A group named Logo, and a textFrame named client.

Layer
    Logo

    client

I convert the textframe to outlines, and now I have:

-A group named Logo, and a group simply named <group>.

Layer
    Logo

   <group>

Assuming:

var currentPage = app.activeDocument.pages[i];
 

My problem is that while logic dictatates Logo would be currentPage.pageItems.item(0), that IS NOT always the case.  Sometimes it's 0, sometime it's 1.

What I'd like to do is 

      currentPage.pageItems.item(0).select;

but with the the item label

     currentPage.pageItems.itemByName("<group>").select()
 
But that does not work. 
guess the issue is that "<group>" is technially not a label?
Any thoughts?
TOPICS
Scripting

Views

408

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 , Jul 24, 2020 Jul 24, 2020

If you use the code that you posted i.e.

app.activeDocument.select(NothingEnum.NOTHING);
currentPage.pageItems.everyItem().select();

All items on the currentPage will be selected and the items can be iterated by the collection app.selection. To check the no. of selected objects use

app.selection.length

So each object would be stored as an element of app.selection array, hence to iterate you use something like

for(var i = 0; i < app.selection.length; i++)
{
 var selObj = app.selection[i] //This i
...

Votes

Translate

Translate
Community Expert ,
Jul 23, 2020 Jul 23, 2020

Copy link to clipboard

Copied

Yes you are correct the default names that appear on creation of any element are not actual names, so <group> can't be accessed via itemByName

How about iterating the groups collection and picking the one without name. Something like

currentPage.groups

P.S. :- Are you sure that the converted textframe is a group and not a compound path?

 

-Manan

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 ,
Jul 24, 2020 Jul 24, 2020

Copy link to clipboard

Copied

You are correct. It is a compount path...  Does that make a difference in why it's not selecting it?

 

I'm wondering if maybe I understand select incorrectly.  If I select all

 

 
app.activeDocument.select(NothingEnum.NOTHING);
currentPage.pageItems.everyItem().select();
 
That all should be stored in selection[1], no?
 

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 ,
Jul 24, 2020 Jul 24, 2020

Copy link to clipboard

Copied

When you are calling createOutlines(), it returns a page item that you can then name. 

 

var out = someText.createOutlines();
out.name = "myName";
...
var itemAgain = currentPage.pageItems.itemByName("myName");

 

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 ,
Jul 24, 2020 Jul 24, 2020

Copy link to clipboard

Copied

That did not work.?

 

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 ,
Jul 24, 2020 Jul 24, 2020

Copy link to clipboard

Copied

Seems the createOutline method returns an array rather than an object, so the following should work

var out = someText.createOutlines();
out[0].name = "myName";
var itemAgain = currentPage.pageItems.itemByName("myName");
itemAgain.select()

Can you post the code that you have if you still have issues, the code pieces that we are sharing are disconnected pieces there should be more elegant ways of integrating it into your codebase if we can have a look at it.

 

-Manan

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 ,
Jul 24, 2020 Jul 24, 2020

Copy link to clipboard

Copied

LATEST

I forgot we were doing createOutlines on multiple frames at once using aPage.textFrames.everyItem().texts.everyItem().createOutlines();

Yeah, that would create an array; each frame would constitute its own set of outlines. 

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 ,
Jul 24, 2020 Jul 24, 2020

Copy link to clipboard

Copied

Could you use a script label? A logo could be assigned a script label, which would be embedded if you save the logo as snippet, or library item:

 

Screen Shot 14.png

 

 

 

 

 

 

var pi = app.documents[0].allPageItems;
for(i = 0; i < pi.length; i++){
    if (pi[i].label == "Logo") {
       pi[i].select();
    }
}

 

 

 

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 ,
Jul 24, 2020 Jul 24, 2020

Copy link to clipboard

Copied

It doesn't seem so...

The issue is I am converting text to outlines and tring to get the geometricBounds

I seem to only be able to se it with the textbox but not the item in the layers window. When I convert to outlines it's gone.

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 ,
Jul 24, 2020 Jul 24, 2020

Copy link to clipboard

Copied

If you use the code that you posted i.e.

app.activeDocument.select(NothingEnum.NOTHING);
currentPage.pageItems.everyItem().select();

All items on the currentPage will be selected and the items can be iterated by the collection app.selection. To check the no. of selected objects use

app.selection.length

So each object would be stored as an element of app.selection array, hence to iterate you use something like

for(var i = 0; i < app.selection.length; i++)
{
 var selObj = app.selection[i] //This is the object that is selected
}

Hope this clears things out

 

-Manan

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 ,
Jul 24, 2020 Jul 24, 2020

Copy link to clipboard

Copied

It does. I found something similar. It does what I want with out accessing a name, but imagine there is a clean one liner..

 

                for(var z = 0; z < currentPage.allPageItems.length; z++ ){
                    //ignore non-objects
                    try{
                        gb = app.activeDocument.selection[z].geometricBounds;
                        if(gb[2]>lowerLimit){ lowerLimit = gb[2] }
                        if(gb[3]>rightLimit){ rightLimit = gb[3] }
                    }catch(e){continue;}
                }

 

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