Skip to content

Instantly share code, notes, and snippets.

@creold
Last active November 8, 2024 14:10
Show Gist options
  • Save creold/05b7f5cae7f2b258fca0a77de58ca097 to your computer and use it in GitHub Desktop.
Save creold/05b7f5cae7f2b258fca0a77de58ca097 to your computer and use it in GitHub Desktop.
Reset custom names for text objects to display their contents. Adobe Illustrator script
/*
Reset custom names for text objects to display their contents
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;
var doc = app.activeDocument;
var tfs = [];
if (selection.typename === 'TextRange') {
tfs = selection.parent.textFrames;
} else if (selection.length) {
tfs = getTextFrames(selection);
} else if (doc.textFrames.length) {
tfs = doc.textFrames;
}
// No text frames in document
if (!tfs.length) return;
for (var i = 0, len = tfs.length; i < len; i++) {
try {
tfs[i].name = '';
} catch (err) {};
}
// Force object name update in visible Layers panel
tfs[0].translate(10, 0);
tfs[0].translate(-10, 0);
}
// Get TextFrames array from collection
function getTextFrames(coll) {
var tfs = [];
for (var i = 0, len = coll.length; i < len; i++) {
if (/text/i.test(coll[i].typename)) {
tfs.push(coll[i]);
} else if (/group/i.test(coll[i].typename)) {
tfs = tfs.concat(getTextFrames(coll[i].pageItems));
}
}
return tfs;
}
// Run script
try {
main();
} catch (e) {}
@creold
Copy link
Author

creold commented Aug 22, 2023

More about script in Telegram channel.

ResetTextNames

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