Answered
copy selected layer names (sub layers), by Script ?
Helllo Friends,
is there a way to copy selected layer names (sub layers), by Script ?

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) 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) {}
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.