Skip to content

Instantly share code, notes, and snippets.

@creold
Last active March 12, 2024 13:24
Show Gist options
  • Save creold/23ac4d87bd1d3039c050a20af218dae1 to your computer and use it in GitHub Desktop.
Save creold/23ac4d87bd1d3039c050a20af218dae1 to your computer and use it in GitHub Desktop.
Move the content of the active artboard to a new layer in Adobe Illustrator
/*
Move the content of the active artboard to a new layer
Discussion: https://community.adobe.com/t5/illustrator-discussions/move-layers-groups-and-masks-to-new-layer/td-p/13256473
Author: Sergey Osokin, email: hi@sergosokin.ru
Check my other scripts: https://github.com/creold
Donate (optional):
If you find this script helpful, you can buy me a coffee
- via Buymeacoffee https://www.buymeacoffee.com/aiscripts
- via DonatePay https://new.donatepay.ru/en/@osokin
- via Donatty https://donatty.com/sergosokin
- via YooMoney https://yoomoney.ru/to/410011149615582
- via QIWI https://qiwi.com/n/OSOKIN
*/
//@target illustrator
app.preferences.setBooleanPreference('ShowExternalJSXWarning', false); // Fix drag and drop a .jsx file
// Main function
function main() {
if (!/illustrator/i.test(app.name)) {
alert('Error\nRun script from Adobe Illustrator');
return false;
}
if (!documents.length) {
alert('Error\nOpen a document and try again');
return false;
}
var doc = activeDocument;
selection = null;
redraw();
doc.selectObjectsOnActiveArtboard();
if (selection.length) {
var idx = doc.artboards.getActiveArtboardIndex(),
lyr = doc.layers.add();
lyr.name = doc.artboards[idx].name;
lyr.color = selection[0].layer.color;
for (var i = 0; i < selection.length; i++) {
selection[i].move(lyr, ElementPlacement.PLACEATEND);
}
selection = null;
redraw();
}
}
// Run script
try {
main();
} catch (e) {}
@creold
Copy link
Author

creold commented Oct 18, 2022

ArtboardToNewLayer

@creold
Copy link
Author

creold commented Oct 18, 2022

Alexander Ladygin has a similar script artboardItemsMoveToNewLayer, which has additional options in the dialog mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment