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.
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 =
...
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
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]);
}
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 = [];
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.
Copy link to clipboard
Copied
Can you record a video or GIF? I don't see any problem with the artboards.
Copy link to clipboard
Copied
Hey, here is the screenshoot before and after running the script. Thank you
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();
}
Copy link to clipboard
Copied
Hey thank you, this works perfect 🙂
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...
Copy link to clipboard
Copied
Nice, thank you