Skip to main content
Inspiring
November 10, 2015
Answered

Is it possible to use scripting to duplicate a layer?

  • November 10, 2015
  • 1 reply
  • 1240 views

I recently asked this question in the Illustrator forum as I didn't realize there was a separate scripting forum: Find and Replace Text Problem

I ended up just hunkering down and solving my own problem after spending a few hours just experimenting with the Scripting guide.

Now, I'm trying to finish the last piece of the puzzle for this script that would totally fix my issue. Is it possible to make the script duplicate a layer? There is a duplicate() function but it doesn't appear to apply to the Layer element. Is there some workaround?

Thanks for your help

Michael

This topic has been closed for replies.
Correct answer Silly-V

Regarding javascript:
With CS5-, you must name a new layer, call it the same name as your source layer for the naming, and then duplicate every item from the source to the new layer.

Be aware that things such as graphic styles applied to layers, opacity masks on layers, and sub-layers won't get carried over like this.

However, with CS6+ which allows a script to play an action, you can actually get "the whole enchilada" by recording an action where you go to the flyout menu and use the "Duplicate" command. This will record "Layers > Duplicate Selection" into the action. Then, you may use javascript to target your desired layer and play this action. Your new layer will have a " copy" string added to it automatically, so you may choose to remove or alter that.

1 reply

Silly-V
Silly-VCorrect answer
Legend
November 10, 2015

Regarding javascript:
With CS5-, you must name a new layer, call it the same name as your source layer for the naming, and then duplicate every item from the source to the new layer.

Be aware that things such as graphic styles applied to layers, opacity masks on layers, and sub-layers won't get carried over like this.

However, with CS6+ which allows a script to play an action, you can actually get "the whole enchilada" by recording an action where you go to the flyout menu and use the "Duplicate" command. This will record "Layers > Duplicate Selection" into the action. Then, you may use javascript to target your desired layer and play this action. Your new layer will have a " copy" string added to it automatically, so you may choose to remove or alter that.

Inspiring
November 10, 2015

Does that apply to CC 2014? That's the version I'm using.

—Michael
Silly-V
Legend
November 10, 2015

Oh yea, absolutely.

Here's the thread where you can see an example of playing action from the script:

Re: Applecript or Javascript to load action set