Skip to content

Instantly share code, notes, and snippets.

@creold
Last active March 12, 2024 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save creold/9d4432746cd0342e0b952b3148706eee to your computer and use it in GitHub Desktop.
Save creold/9d4432746cd0342e0b952b3148706eee to your computer and use it in GitHub Desktop.
Move selected objects from groups to top of layer. Adobe Illustrator script
/*
Moves selected objects from groups to top of layer
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 Donatty https://donatty.com/sergosokin
- via DonatePay https://new.donatepay.ru/en/@osokin
- via YooMoney https://yoomoney.ru/to/410011149615582
*/
//@target illustrator
app.preferences.setBooleanPreference('ShowExternalJSXWarning', false); // Fix drag and drop a .jsx file
// Main function
function main() {
if (!documents.length) {
alert('No documents\nOpen a document and try again', 'Script error');
return;
}
if (!selection.length || selection.typename === 'TextRange') {
alert('Nothing selected\nPlease, select at least one object', 'Script error');
return;
}
var doc = activeDocument,
sel = doc.selection,
len = sel.length,
prnt, lay;
for (var i = 0; i < len; i++) {
prnt = sel[i].parent;
lay = getTopLayer(sel[i]);
if (prnt.typename === "GroupItem" && prnt.parent.typename !== "PluginItem") {
sel[i].move(lay, ElementPlacement.PLACEATBEGINNING);
}
}
}
// Get top-level parent layer
function getTopLayer(item) {
if (item.parent.typename === 'Document') return item;
else return getTopLayer(item.parent);
}
// Run script
try {
main();
} catch (err) {}
@creold
Copy link
Author

creold commented Feb 4, 2023

MoveFromGroupsToLayers

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