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

Move Layers - Groups and Masks to New Layer

Explorer ,
Oct 10, 2022 Oct 10, 2022

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
873
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

correct answers 2 Correct answers

Enthusiast , 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 =
...
Translate
Enthusiast , 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

Translate
Adobe
Guide ,
Oct 10, 2022 Oct 10, 2022

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]);
}
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
Enthusiast ,
Oct 10, 2022 Oct 10, 2022

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

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

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.

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

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

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

Screenshot_1.pngScreenshot_2.png

 

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

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
Enthusiast ,
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 = doc.layers.add();
  lyr.name = lyrName;
  for (var i = 0; i < selection.length; i++) {
    selection[i].move(lyr, ElementPlacement.PLACEATEND);
  }
  selection = [];
  redraw();
}

 ArtboardToNewLayer.gif

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

Hey thank you, this works perfect 🙂

 

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
Enthusiast ,
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/artboardItemsMoveToNe...
Screenshot(2).png

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

Nice, thank you

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