Copy link to clipboard
Copied
Helllo Friends,
is there a way to copy selected layer names (sub layers), by Script ?
//@target illustrator
app.preferences.setBooleanPreference('ShowExternalJSXWarning', false); // Fix drag and drop a .jsx file
// Main function
function main() {
if (!documents.length) return;
if (!selection.length || selection.typename === 'TextRange') return;
var doc = app.activeDocument;
var sel = app.selection;
var names = [];
for (var i = 0; i < sel.length; i++) {
var str = getName(sel[i]);
if (!isEmpty(str)) names.push(getName(sel[i]));
}
if (names.length) setCli
...
Copy link to clipboard
Copied
//@target illustrator
app.preferences.setBooleanPreference('ShowExternalJSXWarning', false); // Fix drag and drop a .jsx file
// Main function
function main() {
if (!documents.length) return;
if (!selection.length || selection.typename === 'TextRange') return;
var doc = app.activeDocument;
var sel = app.selection;
var names = [];
for (var i = 0; i < sel.length; i++) {
var str = getName(sel[i]);
if (!isEmpty(str)) names.push(getName(sel[i]));
}
if (names.length) setClipboard(names.join('\n'));
}
// Get item name of different types
function getName(item) {
var str = '';
if (item.typename === 'TextFrame' && isEmpty(item.name) && !isEmpty(item.contents)) {
str = item.contents;
} else if (item.typename === 'SymbolItem' && isEmpty(item.name)) {
str = item.symbol.name;
} else {
str = item.name;
}
return str;
}
// Check empty string
function isEmpty(str) {
return str.replace(/\s/g, '').length == 0;
}
// Copy dummy TextFrame content to clipboard
// Function by Tom Scharstein https://github.com/Inventsable
function setClipboard(str) {
var prev = app.selection;
selection = null;
var idoc = app.activeDocument;
var tlayer = idoc.layers.add();
var tframe = tlayer.textFrames.add();
tframe.contents = str.replace(/^\s*||\s*$/, "");
tframe.translate(10);
tframe.selected = true;
app.copy();
tlayer.remove();
app.selection = prev;
}
// Run script
try {
main();
} catch (e) {}
Copy link to clipboard
Copied
Yes, Perfectly work as per need, Thank you so much @Sergey Osokin Amezing!
Copy link to clipboard
Copied
I also have an update to BatchRenamer v.1.4 where you can export object names to TXT instead of copying them to the clipboard.
Copy link to clipboard
Copied
Thank you, this will be great help