Last active
November 8, 2024 14:14
-
-
Save creold/e1bc2f83bb281eecb24e29a71c5d4478 to your computer and use it in GitHub Desktop.
Replace top text frame contents within selected group with its name. 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
/* | |
Replaces top text frame contents within selected group with its name | |
Author: Sergey Osokin, email: [email protected] | |
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 (!/illustrator/i.test(app.name)) return; | |
if (!documents.length) return; | |
if (!selection.length || selection.typename === 'TextRange') return; | |
for (var i = 0, len = selection.length; i < len; i++) { | |
var item = selection[i]; | |
if (item.typename !== 'GroupItem') continue; | |
var tf = getFirstTF(item); | |
if (tf == undefined) continue; | |
var name = item.name; | |
if (name.length > 0) tf.contents = name; | |
} | |
} | |
// Get first TextFrame in GroupItem | |
function getFirstTF(grp) { | |
var tf; | |
if (grp.textFrames.length) { | |
for (var i = 0; i < grp.textFrames.length; i++) { | |
return grp.textFrames[i]; | |
} | |
} | |
if (grp.groupItems.length) { | |
for (var i = 0; i < grp.pageItems.length; i++) { | |
if (grp.pageItems[i].typename === 'GroupItem') { | |
tf = getFirstTF(grp.pageItems[i]); | |
} | |
} | |
} | |
return tf; | |
} | |
// Run script | |
try { | |
main(); | |
} catch (err) {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
More about script in Telegram channel.