This content has been marked as final.
Show 3 replies
-
1. Re: Illustrator Script: How can I duplicate a layer ( with sublayers ) with javascript code ?
imagecollection Dec 2, 2014 5:40 PM (in response to klaszlo2004)Not sure that you can in one command.
have a look at this thread and see if it helps:
-
2. Re: Illustrator Script: How can I duplicate a layer ( with sublayers ) with javascript code ?
klaszlo2004 Dec 2, 2014 10:30 PM (in response to imagecollection)Thanks for your answer.
- #target illustrator
- var docRef = app.activeDocument;
- var ln = 'Layer 1';
- var ol = docRef.layers.getByName(ln);
- var nl = docRef.layers.add();
- nl.name = ln+' Copy';
- for (var a = ol.pageItems.length-1; a >= 0; a--) {
- ol.pageItems[a].duplicate(nl, ElementPlacement.PLACEATBEGINNING);
- }
The problem with this code is, that it can't duplicate also the sublayers, and the sublayer elements.
Sure I can write a recursive function, but I think there should exist a duplicate function somewhere ( for Photoshop script exist ! ) or a small trick, but I can't find it.
Thanks
-
3. Re: Illustrator Script: How can I duplicate a layer ( with sublayers ) with javascript code ?
CarlosCanto Dec 2, 2014 11:06 PM (in response to klaszlo2004)you can't compare PS or InD scripting to Illustrator, they're much better supported than Illustrator is.
small trick...create a new action, duplicate a layer (via layer's panel menu), stop recording. Write a script to play such action (it will duplicate the Active Layer).


