Copy link to clipboard
Copied
I would like to know if there is a way to retain the names of text objects/layers when the text is converted to outlines, using scripting.
I create files with dozens of text layers (player names on the back of sports jerseys) and have to send the .ai file to the manufacturers. This means that I have to outline the text, but when I do so, the layers all lose their names and all become "<Group>".
Can anyone think of a way to name these layers with the text they contain?
Hi openbracket​,
it's impossible, if the text is outlined.
But it is possible for text and outline the text through script (be sure that the selected text is only filled and without stroke and/or effects)
You can try something like this:
...// required: an opened document with one selected text frame
var aDoc = app.activeDocument;
var aSel = aDoc.selection;
if (aSel[0].typename =="TextFrame") {
if (aSel[0].characters.length < 40) {
var newName = aSel[0].contents;
} else {
newName = aSel[0].con
Copy link to clipboard
Copied
Hi openbracket​,
it's impossible, if the text is outlined.
But it is possible for text and outline the text through script (be sure that the selected text is only filled and without stroke and/or effects)
You can try something like this:
// required: an opened document with one selected text frame
var aDoc = app.activeDocument;
var aSel = aDoc.selection;
if (aSel[0].typename =="TextFrame") {
if (aSel[0].characters.length < 40) {
var newName = aSel[0].contents;
} else {
newName = aSel[0].contents.substr(0, 39);
}
aSel[0].createOutline();
aSel = aDoc.selection;
// name of the new Group = contents or part of contents of selected text frame
aSel[0].name = newName;
}
Have fun
Copy link to clipboard
Copied
Wow, thanks for that pixxxel schubser​. I think I can tell what's going on in there. I'll give it a go!
Copy link to clipboard
Copied
Thank you so much for your code! It got me started on the route to a solution:
var doc = app.activeDocument; // the document with only the items you want to outline
doc.selectObjectsOnActiveArtboard( ); // select all items on the artboard
for (var i = 0; i < app.selection.length; i++) { // loop through all selected items
if (app.selection.characters.length < 40) { // if the name is less than 40 char
var newName = app.selection.contents; // name it with the contents
} else {
newName = app.selection.contents.substr(0, 39); // otherwise name it with the first 40 char of the contents
}
app.selection.createOutline(); // then create outlines from the text
app.selection.name = newName; // name the layer with the text we saved
}
This code selects all the items, then loops through them. At present I will create a file with ONLY the text objects I want to outline, then paste them back into the main document, but at some stage I may adapt the code to outline the text on a specific layer of my main file.
Thanks again!
openbracket
Copy link to clipboard
Copied
Hi @pixxxelschubser When creating a text from Illustrator. It will be creating a new layer with same name as the text. But whenever we change the text content then layer name changed accordingly. Can we keep layer name when changing the text content?