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

Illustrator Script: How can I duplicate a layer ( with sublayers ) with javascript code ?

New Here ,
Dec 02, 2014 Dec 02, 2014

Dear All

I want to duplicate a layer structure, as the "Duplicate Layer" submenu do with Javascript code, but I can't.

I can duplicate only PageItems or selected object, but no Layers.

Anybody knows how can I do it ?

TOPICS
Scripting
3.0K
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
Guide ,
Dec 02, 2014 Dec 02, 2014

Not sure that you can in one command.

have a look at this thread and see if it helps:

duplicate layer to different document

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 ,
Dec 02, 2014 Dec 02, 2014

Thanks for your answer.

  1. #target illustrator 
  2.  
  3. var docRef = app.activeDocument; 
  4.  
  5. var ln = 'Layer 1'
  6.  
  7. var ol = docRef.layers.getByName(ln); 
  8.  
  9. var nl = docRef.layers.add(); 
  10.  
  11. nl.name = ln+' Copy'
  12.  
  13. for (var a = ol.pageItems.length-1; a >= 0; a--) { 
  14.  
  15.     ol.pageItems.duplicate(nl, ElementPlacement.PLACEATBEGINNING); 
  16.  

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

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 ,
Dec 02, 2014 Dec 02, 2014
LATEST

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).

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