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

Adobe Illustrator Script - Find and Replace Layer Names / XML ID

New Here ,
Feb 06, 2020 Feb 06, 2020

Question, how do you go about getting the XML ID and then setting it via a script?

 
I had hit up a freelancer to help, but he said it wasnt possible, only the layer name was exposed. Which to me doesnt make sense why you wouldnt expose the XML id which is the unique identifier.

Task
We have an Adobe Illustrator file with structured layers, all layers have a prefix.
Layers are grouped and there are multiple levels to the layers.
 
The ultimate outcome is to then export the file as an SVG to then allow for software to adjust the CSS based on database informaiton from a unique identifer we have as the suffix of each layer

We have configured the file so we manage the naming of the layers via XML ID
Preferences -> Units -> Identify Objects By -> XML ID

Layer Naming and Structure Example:
{Prefix}_{id}
Layer_group_1987
      Layer_floor_1987
      Layer_roof_1987

When we duplicate the layers it adds on a suffix in the convention of _1, _2, _3 etc,
The objective for us is to then duplicate the layer and change the {id} value, but we may have 50 layers that needs updating.

Currently duplicates come up as per below.
Layer_group_1987_1
      Layer_floor_1987_1
      Layer_roof_1987_1
Layer_group_1987_2
      Layer_floor_1987_2
      Layer_roof_1987_2
Layer_group_1987_3
      Layer_floor_1987_3
      Layer_roof_1987_3

We would like a script that will allow us to search and replace in bulk, looping through all layer names and changing a specific string in the layers.
1) user prompt form - enter in string we wish to replace on the layers, and what value we wish to replace with
for example
Find variable = "_1987_1"
Replace variable = "_1990"
2) On user prompt form submit, run through all layers in the file, and search/replace using the variables in step 1.
ie
Layer_group_1987_1 -> Layer_group_1990
      Layer_floor_1987_1 -> Layer_floor_1990
      Layer_roof_1987_1 -> Layer_roof_1990


Some additional resources from the Adobe community we have found online that appears to have a similar logic.

Resources:
community.adobe.com/t5/illustrator/a-script-to-find-and-replace-layer-names/td-p/4960031
https://www.adobe.com/devnet/illustrator/scripting.html

Using the latest Adobe Illustrator 2020
TOPICS
Scripting
1.3K
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
Adobe
Contributor ,
Feb 06, 2020 Feb 06, 2020

Basically what i've found is that even when using the XML naming, there is only one function to get the layers:

app.activeDocument.layers.getByName('Layer');
app.activeDocument.layers.getByName('Layer 1');
app.activeDocument.layers.getByName('Layer 2');

 If the names you see in illustrator Layers panel are Layer_1 Layer_2 etc, you still get them with same function, and you have to ignore _ sign.

 

When i'm copying layers it adds copy to the layer name, so i'm not sure how do you copy those, so it's adding _1 etc.

In theory it seems doable, could you please get us some files to check with?

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 ,
Feb 06, 2020 Feb 06, 2020

@lumenn, what I've seen is that when you have XLM id off you can have duplicate layer/objects names, then when you switch xlm id on, illustrator adds  _1_, _2_, etc to duplicates.

 

other than that duplicating always adds "copy"

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
New Here ,
Feb 13, 2020 Feb 13, 2020
LATEST

So we were able to make a script that in large cleaned up the layers/objects pending the file was built in XML first then we changed the units from XML ID to Object Name.

 

Ran the rename script against the layer names, this in bulk changes the core layer names

Then changed the back to XML ID in units

 

But yes, this duplication thing is a huge pain, adding on suffix of _1_, _2_, _3_ etc where ever we duplicated a layer group.

 

My original through was, it disappeared when we made the object name unique, but it has tagged it somehow in XML ID   

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