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

Move Layers - Groups and Masks to New Layer

New Here ,
Oct 10, 2022 Oct 10, 2022

Copy link to clipboard

Copied

I have problem writing a code to move all layers from active Artboard to New Layer, and retain layer masks and groups? I only manage to do that without groups or masks. Please help if you have some information about that.

Thank you.

TOPICS
Scripting

Views

156

Likes

Translate

Translate

Report

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

correct answers 2 Correct answers

Contributor , Oct 17, 2022 Oct 17, 2022

I understand the problem. An old Adobe bug where objects on the artboard are selected before the script runs and then re-selected by the script. Added a fix. I also made a new layer name from the artboard name.

var doc = activeDocument;
var idx = doc.artboards.getActiveArtboardIndex();
var lyrName = doc.artboards[idx].name; // Get new layer name from the active artboard

selection = [];
redraw(); // Fix selected objects bug
doc.selectObjectsOnActiveArtboard();

if (selection.length) {
  var lyr =
...

Likes

Translate

Translate
Contributor , Oct 18, 2022 Oct 18, 2022

Also, Alexander Ladygin has a similar script, which has additional options in dialog mode https://raw.githubusercontent.com/alexander-ladygin/illustrator-scripts/master/artboardItemsMoveToNewLayer.jsx
Screenshot(2).png

Likes

Translate

Translate
Advisor ,
Oct 10, 2022 Oct 10, 2022

Copy link to clipboard

Copied

Can you give more details?  The snippet below moves all layers to a new layer and, for me, retains groups and clipping masks. 

var doc = app.activeDocument;
doc.layers.add().name = "Layer 1";
for (var i = doc.layers.length - 1; i > 0; i--) {
    doc.layers[i].moveToBeginning(doc.layers[0]);
}

Likes

Translate

Translate

Report

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
Contributor ,
Oct 10, 2022 Oct 10, 2022

Copy link to clipboard

Copied

Do you want the contents of the active artboard to be moved in a new layer? If I understand the task correctly. Try this code, but it only works with visible and unlocked objects on the artboard.

var doc = activeDocument;
var newLayer = doc.layers.add();
newLayer.name = "Moved";
selection = [];
doc.selectObjectsOnActiveArtboard();
for (var i = 0; i < selection.length; i++) {
  selection[i].move(newLayer, ElementPlacement.PLACEATEND);
}
selection = [];

move-artboard-obj-to-new-layer.gif

Likes

Translate

Translate

Report

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 ,
Oct 13, 2022 Oct 13, 2022

Copy link to clipboard

Copied

Thank you for your answers, but this script in my case release all group and clipping to single objects. Try to add one more Artboard, set that new Artboard to be active, and add all the elements to it. You will see that content is released to single objects.

Likes

Translate

Translate

Report

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
Contributor ,
Oct 13, 2022 Oct 13, 2022

Copy link to clipboard

Copied

Can you record a video or GIF? I don't see any problem with the artboards.

Likes

Translate

Translate

Report

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 ,
Oct 16, 2022 Oct 16, 2022

Copy link to clipboard

Copied

Screenshot_1.pngScreenshot_2.png

 

Hey, here is the screenshoot before and after running the script. Thank you

Likes

Translate

Translate

Report

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
Contributor ,
Oct 17, 2022 Oct 17, 2022

Copy link to clipboard

Copied

I understand the problem. An old Adobe bug where objects on the artboard are selected before the script runs and then re-selected by the script. Added a fix. I also made a new layer name from the artboard name.

var doc = activeDocument;
var idx = doc.artboards.getActiveArtboardIndex();
var lyrName = doc.artboards[idx].name; // Get new layer name from the active artboard

selection = [];
redraw(); // Fix selected objects bug
doc.selectObjectsOnActiveArtboard();

if (selection.length) {
  var lyr = doc.layers.add();
  lyr.name = lyrName;
  for (var i = 0; i < selection.length; i++) {
    selection[i].move(lyr, ElementPlacement.PLACEATEND);
  }
  selection = [];
  redraw();
}

 ArtboardToNewLayer.gif

Likes

Translate

Translate

Report

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 ,
Oct 17, 2022 Oct 17, 2022

Copy link to clipboard

Copied

Hey thank you, this works perfect 🙂

 

Likes

Translate

Translate

Report

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
Contributor ,
Oct 18, 2022 Oct 18, 2022

Copy link to clipboard

Copied

Also, Alexander Ladygin has a similar script, which has additional options in dialog mode https://raw.githubusercontent.com/alexander-ladygin/illustrator-scripts/master/artboardItemsMoveToNe...
Screenshot(2).png

Likes

Translate

Translate

Report

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 ,
Oct 20, 2022 Oct 20, 2022

Copy link to clipboard

Copied

LATEST

Nice, thank you

Likes

Translate

Translate

Report

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