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

Quick question for a beginner

Guest
Mar 23, 2011 Mar 23, 2011

Hi everyone,

I spent about half a day looking for what I want. I've been reading the Illustrator scripting guide, and browsed forums but I can't find an answer so here is my question :

I have a file in Illustrator.

I have 3 layers in this file called "L", "M" and "S" (for sizes).

In each layer, there are two text elements with something written inside.They are always named "Name" and "Number". I created everything using my mouse and keybord, no script.

It looks like :

L (layer)

     Name (text)

     Number (text)

M (layer)

     Name (text)

     Number (text)

S (layer)

     Name (text)

     Number (text)

I want to select one specific Name in layer M for example. I can't find a way to do it...

var myDoc = app.activeDocument
var myLayer = myDoc.layers[1] /* myLayer is "M" */

I read that it is possible to access the wanted textframe by using : myDoc.textFrames[2]  /* 2 refers to the third text element in the document textframes. */

My problem is that I can have a bigger file with tons of other textframes, so I'd like to get the one called "Name" in the "M" Layer without knowing its rank in the document textframes.

I tried var myText = myDoc.myLayer.textFrame but obviously myLayer doesn't have textframes, it only works with documents, or I miss something.

I hope you guys understand my problem.

Thank you for your help.

TOPICS
Scripting
1.2K
Translate
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 , Mar 23, 2011 Mar 23, 2011

Hi totom, welcome to the forum

Layers do have textFrames, you were really close, here's the syntax for doing what you want

var idoc = app.activeDocument;
var ilayer = idoc.layers["M"];
var iframe = ilayer.textFrames["Name"];

iframe.selected = true;
Translate
Adobe
Community Expert ,
Mar 23, 2011 Mar 23, 2011

Hi totom, welcome to the forum

Layers do have textFrames, you were really close, here's the syntax for doing what you want

var idoc = app.activeDocument;
var ilayer = idoc.layers["M"];
var iframe = ilayer.textFrames["Name"];

iframe.selected = true;
Translate
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
Guest
Mar 23, 2011 Mar 23, 2011

Awesome, thank you very much CarlosCanto. It works great!

It kinda pisses me off having spent that much time on something so easy. Thanks again

Translate
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 ,
Mar 23, 2011 Mar 23, 2011

you're welcome, don't get discouraged, that's how it works....very slow at the beggining, that's a normal learning curve.

Translate
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
Guest
Mar 23, 2011 Mar 23, 2011

I've been programming in quite a few languages so far, but never in Javascript and especially javascript for Illustrator ^^

I'm planning on writting a nice little script to save me quite some time. I'm really motivated so it should help. My main problem was to be able to select items. Now that I'm good to go, it should go faster

Thanks again.

Translate
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
Guide ,
Mar 23, 2011 Mar 23, 2011

There is very little need to use 'selection' you only need target an item correctly in order to manipulate it…

Translate
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 ,
Mar 23, 2011 Mar 23, 2011

Oh, man....  this was driving me nuts.  This script wasn't working for me. It was hanging on the line "var iframe = ilayer.textFrames["Name"];".  Turns out I had to rename the text object before the script could see the name (even though it showed up as named in the AI object Options dialog).  This appears to be true for any object.  They all appear to get default names, but they aren't names a script will see.  You have to rename the object for a script to see the name.  Maybe someone can verify that for me, or perhaps that I'm just loopy.

Also, in the CS5 Scripting Reference it doesn't even show that textFrameItems have a name property.  That was the first thing that through me off.  When the script didn't work I thought, of course it doesn't work, textFrameItems don't have a name property.  Turns out they do

Translate
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
Guide ,
Mar 23, 2011 Mar 23, 2011

You should look at 'pageItems' you will see that there are super classes from which other classes inherit properties…

Translate
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 ,
Mar 23, 2011 Mar 23, 2011

Ahhh, yes....  still getting the hang of object oriented programming   But still, in the Scripting Reference everything else (including legacyTextItems) shows a name property, but not for textFrameItems.  That's what threw me off.  Thanks for setting me straight.

Can you confirm the item naming anomoly?  Items appear to be named, but not really until you enter a new name.

Translate
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 ,
Mar 23, 2011 Mar 23, 2011

Red, sorry about that, I didn't think of it. I wasn't aware it is not in the Documentation, I come from VB and usually work on a VB version first then rewrite to JS, I just love the VB IDE (don't like at all the ESTK). It turns out THERE IS a name property in the VBS documentation, I'm not sure what's going on, there's a bunch on differences between the two.

About the naming thing, what you see in the layers palette is not a name, but more like a "preview" of the text, if not explicitly named, the name property returns "null" (I guess, or an empty string, but not a name).

JSvsVBS.PNG

Translate
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 ,
Mar 23, 2011 Mar 23, 2011
LATEST

Yes, those "names" in the layers pallette aren't really names, and scripts return null (or something).  Until you edit the name.  Then it becomes an actual item name that the script can see.  And it's not just text, it's all the items (paths, groups, etc.) in the layers pallette.  Text items just happen to show the textFrame contents.  Somewhat odd.  But now that it's understood, it's not a problem.  Good to see that it wasn't just happening to me though.  Thanks.

Translate
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