Copy link to clipboard
Copied
Hi All,
Multiple layers in an illustrator file can have the same name. So the layer name cannot be a unique identifier for layers. Is there a way to extract a unique identifier for layers through scripting? I saw that if the 'Identify Objects by' property (inside Preferences -> Units) is set to XML ID, all layer names, even identical ones are replaced by some unique ids. Can we extract these ids via scripting without manually changing the 'Identify Objects by' property. Basically, extraction of any unique identifier for illustrator layers would serve the purpose. I am really stuck with this and need help urgently. Any help would be highly appreciated.
Thanks in advance.
Copy link to clipboard
Copied
Hi I have just asked this same question Access XML_ID of pageItem/groupItem before seeing this one.
Did you ever find a solution?
Copy link to clipboard
Copied
Hi Michael,
Unfortunately I never got the solution as to how we can access the XML ID. I resorted to generating by own id for the layers. It is not exactly an ideal solution but suffices my purpose. Though I would love to know if at all there is a way to extract the unique id .
Thanks.
Copy link to clipboard
Copied
Not sure if this is what your after, but under Preferences there is an option to "Identify Objects By: Object Name or XML ID"
I only just noticed it so not sure if it helps in any way
Copy link to clipboard
Copied
Hello,
I was actually trying to access this unique id using Extendscript. That's where I was stuck as I could not find which property in the Illustrator DOM would give me the value for XML ID.
Thanks.
Copy link to clipboard
Copied
Hi all, I am sorry to bring about gloom, but it is my opinion that the (Identify by Object Name or XML_ID) is purely for input purposes while you're using Illustrator to draw. The preference controls how you can input new names (Unique name, no spaces, no start with number, etc) and makes changes to existing names to convert to the new preference. The name is now in the format of an XML_ID, so your pageItem.name is still what reflects the object's xml id.
Copy link to clipboard
Copied
When I found this I noticed it changed the name of the layers in the layers pallet.
I had not had a chance to test this with code.
If "use XML ID" is turned on then you are not able to name layers the same thing.
this in turn would follow through to your script using layer.name
for existing files you would need to fix names manually or...
I am sure it would be possible to Script.
eg. export SVG file and pull the layer ID's from that and rename the document layers accordingly. (may be a little tricky for sublayers, but top level layers should be straight forward)
Then as long as "use XML ID" is left on the files would not need this run again as you cannot use duplicate layer names.