質問

I am relatively new to scripting for illustrator and I am having a hard time wrapping my head around it.

I would like to select some text (the whole range) and set some attributes to it.

I have named the text object in the layers panel and if possible, I would like to select it by name. (or any other easy/direct way you may suggest)

This is how I reference my objects by name.

 doc = app.activeDocument;
 doc.pageItems.getByName('myname');

I was hoping I could do keep it simple like so....

 doc.pageItems.getByName('myname').characterAttributes.size = 30;

Needless to say, this doesn't seem to work. I was looking into making characterStyles as well but that is much more complex so setting individual attributes would be my first step.

Any help would be greatly appreciated!

役に立ちましたか?

解決

Ok, so I figured it out.... I was missing the .textRange selector.

 doc.pageItems.getByName('myname').textRange.characterAttributes.size = 500;

This works great for most all of the attributes, I still can't seem to set the .textFont attribute by the font name. I can set it using the index, but that's no good as I update my fonts quite often.

 doc.pageItems.getByName('myname').textRange.characterAttributes.textFont = app.textFonts[7];

Even after retrieving the name of the font, I can't set it... I assumed the way would be something like...

 doc.pageItems.getByName('myname').textRange.characterAttributes.textFont = "Arial";

No Luck Though...

他のヒント

You can use getByName(name) where name is the font's full name (i.e. including font style) as opposed to family name:

textRef.textRange.characterAttributes.textFont = app.textFonts.getByName("FiraSans-Book");

You can set attributes with:

doc.pageItems.getByName('myname').setAttribute("id","foo");

Source: http://www.w3schools.com/jsref/met_element_setattribute.asp

You can set the style with:

doc.pageItems.getByName('myname').style.fontSize = "medium";

The whole list of things you can put behind '.style' is here: http://www.w3schools.com/jsref/dom_obj_style.asp

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top