• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

copy selected layer names (sub layers), by Script ?

Engaged ,
Oct 09, 2023 Oct 09, 2023

Copy link to clipboard

Copied

Helllo Friends,

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

jkhakase_0-1696835474897.png

 

TOPICS
How-to , Scripting

Views

370

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Oct 09, 2023 Oct 09, 2023
//@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
...

Votes

Translate

Translate
Adobe
Enthusiast ,
Oct 09, 2023 Oct 09, 2023

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) {}

namesToClipboard.gif

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 10, 2023 Oct 10, 2023

Copy link to clipboard

Copied

Yes, Perfectly work as per need, Thank you so much @Sergey Osokin Amezing!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 13, 2023 Oct 13, 2023

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.

script.jpg

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 16, 2023 Oct 16, 2023

Copy link to clipboard

Copied

LATEST

Thank you, this will be great help

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines