Last active
March 12, 2024 13:24
-
-
Save creold/9d4432746cd0342e0b952b3148706eee to your computer and use it in GitHub Desktop.
Move selected objects from groups to top of layer. Adobe Illustrator script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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) {} |
Author
creold
commented
Feb 4, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment