Am I doing something wrong or is it a bug?
// Save Name var vName1 = app.activeDocument.textFrames; // Show Name alert (vName1);
Copy link to clipboard
Maybe not you. But it may take more effort on your part to fix it.
By default, text frames are un-named. It doesn't look like that, because Illustrator places the first words/characters inside a text frame into the layer/sub-layer name as a proxy. The proxy appears to name the text frame/layer, but it does not. It serves as the proxy to illustrate there is no name.
I don't know how to name a text frame. But I do know how to name a layer/sub-layer, which may or may not work for your data needs.
Open the Layers panel, as you've shown above, and double-click inside the proxy text for your targeted layer/sub-layer. This highlights all the proxy text, and will replace it with whatever you subsequently type. Let's name it Fred. Now click away, and you'll have a new layer/sub-layer named Fred.
Please note that I don't know if naming a sub-layer with an element on it is the same as naming an element for your data needs. But it will at least give you something to put between the "..." quote marks to find out.
Hope this helps,
thanks for your answer. I need the textframe, but I can get my information from .contents, which is better for my script to come.
You can name a text frame like any other object or container, just double-click the current name (or sudo-name) and rename it to your liking. This does not affect the content of the text frame, but makes it more scriptable. I see Carlos already fully explained this. 🙂
Copy link to clipboard
your text frames are not named, what your see in the layers panel is a preview of their contents.
your variable vName1 holds the actual Text Frame, to query it's name
var vName1 = app.activeDocument.textFrames.name; // this will return an empty string since your frame is not named
if you're trying to get the contents of the frame
var vName1 = app.activeDocument.textFrames.contents; // returns Abc
to name your frame, double click on it in the layers panel and type a name for example "myFrame"
or you can also name it programmatically
app.activeDocument.textFrames.name = "myFrame";
I will use .contents for my solution.
Here's a pretty decent reference manual that's easily searchable and has lots of great links making it easy to navigate from concept to concept so you can see how things are supposed to be strung together.
Here are two more examples:
var aTF = app.activeDocument.textFrames; var vName1 = (aTF.name != "") ? aTF.name : "Sorry, this is an unnamed text frame."; alert (vName1);
var aTF = app.activeDocument.textFrames; var vName1 = (aTF.name != "") ? aTF.name : app.activeDocument.textFrames.name = "New name: " + aTF.contents.slice(0,5) + "…"; alert (vName1);
Try them out and
thanks for the examples. that will help.
have a goot day, jens.