Copy link to clipboard
Copied
Question from a complete n00b:
I need to rename a large number of selected objects/paths. This is because I want to use another script that only works when my objects have the default name, "<Path>". So really, I just need to remove existing names of objects.
This other script is here:
http://kelsocartography.com/blog/?p=325
Of course, I could manually remove names by double-clicking on objects in the layers palette and deleting the name, but that's no fun.
I've found some great scripts for renaming layers, but nothing for non-layer objects.
First, I'm trying to remove names from ALL objects in the document. once that's working, I want to only remove names of selected objects.
Here's my very simple non-working javascript - (the whole thing):
app.activeDocument.pageItem.name = "";
my test Ai file is also really basic: a few rectangles, some of which have been named in the layers palette.
When I run this, I get:
Error 21: undefined is not and object.
Line: 1
-> app.activeDocument.pageItem.name = "";
I've tried a number of other approaches, and either get "undefined is not an object" or nothing happens.
pageItem has "name" as a writable property, so I think it's what to use, but I really don't know what I'm doing - help!
I'd also happy to use actions, but I'm stuck on that too.
-> app.activeDocument.pageItem.name = "";
I've tried a number of other approaches, and either get "undefined is not an object" or nothing happens.
pageItem has "name" as a writable property, so I think it's what to use, but I really don't know what I'm doing - help!
name is a valid property of pageItem, now the script needs to know which pageItem you're refering to, use
app.activeDocument.pageItems[0].name = "";
Copy link to clipboard
Copied
-> app.activeDocument.pageItem.name = "";
I've tried a number of other approaches, and either get "undefined is not an object" or nothing happens.
pageItem has "name" as a writable property, so I think it's what to use, but I really don't know what I'm doing - help!
name is a valid property of pageItem, now the script needs to know which pageItem you're refering to, use
app.activeDocument.pageItems[0].name = "";
Copy link to clipboard
Copied
Thanks!!
Here's my final script:
////START SCRIPT////
//how to use: select objects that you want to rename, then run script
//note - new name may not display until you unselect objects
var docRef = activeDocument;
for (var i=0; i < docRef.pageItems.length; i++)
{
if (docRef.pageItems.selected == true)
{
docRef.pageItems.name = "";
}
}
////END SCRIPT////
currently, it renames with no text. In other words, it removes existing names.
One thing that was messing me up was that new names are not immediately displayed - you have to unselect your selected objects before names in the layers palette refresh.
Copy link to clipboard
Copied
not bad for starters, now what if we have 1000 items and we select 10 to rename? not very efficient
try looping thru the selection instead of all pageItems
var docRef = activeDocument;
var sel = docRef.selection;
for (var i=0; i < sel.length; i++)
sel.name = "";
Copy link to clipboard
Copied
Much better - thank you! (my file has more like 10k items).
I tried something similar but with pageItems, and couldn't make it work. I didn't realize you didn't need pageItems.
Copy link to clipboard
Copied
Hi guys,
I'm new here on forum. I have a problem with naming a large number of objects (not layers).
My object names curently have this format:
Section:100_a
Section:100_b
Section:201_21
etc..
It is possible with a script to replace the "_" with a space and a new word so that the objects will be named as:
Section:100 Subsection:a
Section:100 Subsection:b
Section:201 Subsection:21
The script can be set up to work with only selected objects or all objects within document (whatever is easy).
Thank you in advance,
Adrian
Copy link to clipboard
Copied
Hi Adrian, yes, sure
...Considering you want to rename any kind of pageItems (paths, groups, texts and so on).. an example would be:
var doc = app.activeDocument;
var items = doc.pageItems;
for (var g=0;g<items.length;g++){
items
.name = items .name.replace ("_", " Subsection "); };
app.redraw();
If you want to rename just a kind of object (like paths or groups only) change what "items" variable receive.
P.S: not necessary to select any object. But, after running the script, if the Layers panel do not redraw, try to select and deselect any object....
Let me know if it helps.
Gustavo.
Copy link to clipboard
Copied
Hello Gustavo,
Thank you, it works great:)
Copy link to clipboard
Copied
Can you do like a video tutorial on this. I would love you for ever.
Copy link to clipboard
Copied
Hello again,
Guys I need a small script. I'll be forever grateful if you can help me out.
I want to add a prefix to my object names.
So currently I have the following format:
ExampleName1
ExampleName2
etc...
It needs to be like this:
text ExampleName1
text ExampleName2
So basically to add "text" and a space before the current name.
Thank you in advance!
Adrian
Copy link to clipboard
Copied
same as original example, almost the same, select your items before running the script
- var docRef = activeDocument;
- var sel = docRef.selection;
- for (var i=0; i < sel.length; i++)
- sel.name = "text " + sel.name;
Copy link to clipboard
Copied
Hi Carlos,
Many thanks for this.
The script is great but is not working for text elements. For other elements like paths the script works perfectly.
I have text elements like:
A
B
C1
D235
etc..
The script will rename as follow:
text
text
text
text
.....
So the script add the word "text" but delete the initial name.
I think the script consider that the text objects have no names. Some thing when we have, let's say, a circle. Illustrator automatically name this as <Path>. When I run the script the name will be "text" and not "text <Path>" But when I rename the circle from <Path> to other name, the script works.
Not sure how to solve this text naming, because I don't want to rename the text objects.
Best,
Adrian
Copy link to clipboard
Copied
what you see in the layers panel is either a "preview" of the text contents for Text Elements, or the type of object "<path>" for example, for other elements. These are added by default until the user names the objects.
...so if you haven't explicitly named your paths or text elements, then all you'll see after running the script is
text
text
text
in your case use this instead
sel.name = "text " + sel.contents;
[edit]
that will only work on text elements, it will raise an error if you select path items or other items.
Copy link to clipboard
Copied
Thank you Carlos, I only need text elements to rename. So the script is working like magic ![]()
Once again thank you for your quick replay.
Copy link to clipboard
Copied
Hi guys,
Is there a way to write a script that rename the objects names with lowercase?
For example I have objects with following names:
text_A
text_B1
etc.
I need something that rename like this:
text_a
text_b1
Best,
Adrian
Copy link to clipboard
Copied
AdrianDragne wrote: Is there a way to write a script that rename the objects names with lowercase?
sel.name = sel.name.toLowerCase();
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more