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

SYMBOLS COUNT TABLE

New Here ,
Jun 04, 2018 Jun 04, 2018

It´s possible to make a script that writes a table with all symbols instances count ? how difficult it would be?

TOPICS
Scripting
2.7K
Translate
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 2 Correct answers

People's Champ , Jun 05, 2018 Jun 05, 2018

var main = function() {

var doc;

if ( !app.documents.length ) {

alert("This scripts needs an open document !");

return;

}

doc = app.activeDocument;

var symbols = doc.symbolItems, n = symbols.length, nSymbol, db = {}, arr = [];

while ( n-- ) {

nSymbol = symbols.symbol;

db[ nSymbol.name ]  = db[ nSymbol.name ] || 0;

db[ nSymbol.name ]++;

}

for ( prop in db ) {

arr.push ( prop+" : "+db[prop] );

}

alert( "Result:\r"+arr.join("\r") );

}

main();

Translate
Community Expert , Jul 10, 2020 Jul 10, 2020

moving to the new Forums ruined all existing scripts, try this version

var main = function() { 

 

var doc; 

 

if ( !app.documents.length ) { 

alert("This scripts needs an open document !"); 

return; 

} 

 

 

doc = app.activeDocument; 

 

var symbols = doc.symbolItems, n = symbols.length, nSymbol, db = {}, arr = []; 

 

while ( n-- ) { 

nSymbol = symbols[n].symbol; 

db[ nSymbol.name ]  = db[ nSymbol.name ] || 0; 

db[ nSymbol.name ]++; 

} 

 

 

for ( prop in db ) { 

arr.push ( pr
...
Translate
Adobe
People's Champ ,
Jun 05, 2018 Jun 05, 2018

var main = function() {

var doc;

if ( !app.documents.length ) {

alert("This scripts needs an open document !");

return;

}

doc = app.activeDocument;

var symbols = doc.symbolItems, n = symbols.length, nSymbol, db = {}, arr = [];

while ( n-- ) {

nSymbol = symbols.symbol;

db[ nSymbol.name ]  = db[ nSymbol.name ] || 0;

db[ nSymbol.name ]++;

}

for ( prop in db ) {

arr.push ( prop+" : "+db[prop] );

}

alert( "Result:\r"+arr.join("\r") );

}

main();

Translate
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
New Here ,
Jun 05, 2018 Jun 05, 2018

thank you very much !

I made a little change in the script making illustrator to paste the results in a text frame, because I coulnd´t copy the text from the alert.

var main = function() { 

 

var doc; 

 

if ( !app.documents.length ) { 

alert("This scripts needs an open document !"); 

return; 

 

 

doc = app.activeDocument; 

 

var symbols = doc.symbolItems, n = symbols.length, nSymbol, db = {}, arr = []; 

 

while ( n-- ) { 

nSymbol = symbols.symbol; 

db[ nSymbol.name ]  = db[ nSymbol.name ] || 0; 

db[ nSymbol.name ]++; 

 

 

for ( prop in db ) { 

arr.push ( prop+" : "+db[prop] ); 

var result = doc.textFrames.add();

result.contents = ( "Result:\r"+arr.join("\r") );

result.top = 700;

result.left = 400;

redraw();

 

 

 

main(); 

I´ll try to refine a bit to make a table, but it works anyway.

Thank you !

Translate
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
Explorer ,
Jul 10, 2020 Jul 10, 2020

Hello! 

 

Thank you for these! 

 

I am gettign an error. is it becuase I named my symbols? They are all static graphic symbols

Screen Shot 2020-07-10 at 9.34.34 AM.pngexpand image

Screen Shot 2020-07-10 at 9.51.03 AM.pngexpand image

 

thank you!

Translate
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
Valorous Hero ,
Jul 10, 2020 Jul 10, 2020

That is a strange error, are you running the script as written or did you have anything running before it, or have extra custom code?

Translate
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
Explorer ,
Jul 10, 2020 Jul 10, 2020

I am running it as written. copy and pasted it into sublime text, and then saved it as a .js. 

 

i do not know code so copy and paste is my only option. 

Translate
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
Community Expert ,
Jul 10, 2020 Jul 10, 2020

moving to the new Forums ruined all existing scripts, try this version

var main = function() { 

 

var doc; 

 

if ( !app.documents.length ) { 

alert("This scripts needs an open document !"); 

return; 

} 

 

 

doc = app.activeDocument; 

 

var symbols = doc.symbolItems, n = symbols.length, nSymbol, db = {}, arr = []; 

 

while ( n-- ) { 

nSymbol = symbols[n].symbol; 

db[ nSymbol.name ]  = db[ nSymbol.name ] || 0; 

db[ nSymbol.name ]++; 

} 

 

 

for ( prop in db ) { 

arr.push ( prop+" : "+db[prop] ); 

} 

var result = doc.textFrames.add();

result.contents = ( "Result:\r"+arr.join("\r") );

result.top = 700;

result.left = 400;

redraw();

 

} 

 

 

main(); 
Translate
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
Explorer ,
Jul 10, 2020 Jul 10, 2020

Thank you so much, that worked! 

Translate
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
New Here ,
Nov 05, 2020 Nov 05, 2020

Carlos,

 

Thank you for the excellent script. Is it possible to have the symbol itself show in the resulting list instead of the name? How would a person code that?

 

Thanks, so much.

 

rtvkeith

Translate
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
Community Expert ,
Nov 05, 2020 Nov 05, 2020

Hi keith, what do you mean? can you elaborate?

Translate
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
New Here ,
Mar 08, 2023 Mar 08, 2023

Is there a mac version of this?

Translate
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
Community Expert ,
Mar 08, 2023 Mar 08, 2023

The updated script by Carlos when used on a Mac should work. Two things, if you use TextEdit on the Mac be sure when you save it it is Plain Text not RTF. Use .jsx as the extension.

Translate
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
New Here ,
Mar 08, 2023 Mar 08, 2023

Yes! That worked!

Translate
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
Explorer ,
Mar 08, 2023 Mar 08, 2023

Hey! 

 

it works both on mac (i am on one) 

 

you just need to paste it into text edit and save it as a .js then open in illustrator like any other script 

Translate
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
New Here ,
Mar 08, 2023 Mar 08, 2023

Yes, I was pasting into script editor before and it wouldn't work. Used text editor and converted to Plain Text, added the .jsx at the end and it works as described. I don't think it will do what I needed it to do which is keep a live running tally of multiple different symbols as they are added and removed.

Translate
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
Community Expert ,
Mar 08, 2023 Mar 08, 2023

no, the script runs once and stops, you would need to run it each time it's needed

Translate
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
New Here ,
Mar 08, 2023 Mar 08, 2023

Ok, that's what I thought. I know basically nothing about scripts, but is a "live" script that is constantly running and updating info a possibility? I'm being asked to come up with a way to keep a tally of symbols on a floor plan in Illustrator. 
Screen Shot 2023-03-08 at 11.20.10 AM.pngexpand image

Translate
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
New Here ,
Oct 13, 2023 Oct 13, 2023

Would there also be a way of having this script mention only visible symbols?

Translate
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 the above code by Carlos Canto. And add the following IF check to the WHILE loop:

while (n--) {
  if (symbols[n].hidden == true) continue;
  nSymbol = symbols[n].symbol;
  db[nSymbol.name] = db[nSymbol.name] || 0;
  db[nSymbol.name]++;
}
Translate
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
New Here ,
Oct 13, 2023 Oct 13, 2023

Thanks for assisting! For some reason though, it still returns numbers for all symbol instances; visible and non-visible... 

Translate
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

Full code and a screenshot of the test. If it doesn't work for you, can you show a simple example of what happens for you?

 

var main = function () {
  if (!app.documents.length) {
    alert("This scripts needs an open document !");
    return;
  }

  var doc = app.activeDocument;
  var symbols = doc.symbolItems;
  var n = symbols.length;
  var nSymbol, db = {};
  var arr = [];

  while (n--) {
    if (symbols[n].hidden == true) continue;
    nSymbol = symbols[n].symbol;
    db[nSymbol.name] = db[nSymbol.name] || 0;
    db[nSymbol.name]++;
  }

  for (prop in db) {
    arr.push(prop + " : " + db[prop]);
  }

  var result = doc.textFrames.add();
  result.contents = ("Result:\r" + arr.join("\r"));
  result.top = 700;
  result.left = 400;
  redraw();
}

main();

 

 symbols.pngexpand image

Translate
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
New Here ,
Oct 13, 2023 Oct 13, 2023

I found it only works correctly if all the symbols are in the same layer, as in your screenshot. As soon as I move some symbols to another (inactive/hidden) layer, it starts counting them again.

Translate
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
New Here ,
Oct 13, 2023 Oct 13, 2023

Slight rephrase: it only works for individually hidden symbols, not for symbols that are "active" but in a hidden layer. If that makes any sense... thanks though, it's already a big improvement 🙂

Translate
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

 

function main() {
  var title = "Symbol Instances:";
  var separator = ": ";

  if (!app.documents.length) {
    alert("This scripts needs an open document !");
    return;
  }

  var doc = app.activeDocument;
  var symbols = doc.symbolItems;
  var n = symbols.length;
  var nSymbol, db = {};
  var arr = [];

  while (n--) {
    if (isHidden(symbols[n])) continue;
    nSymbol = symbols[n].symbol;
    db[nSymbol.name] = db[nSymbol.name] || 0;
    db[nSymbol.name]++;
  }

  for (prop in db) {
    arr.push(prop + separator + db[prop]);
  }

  var lay = getEditableLayer(doc);
  var result = lay.textFrames.add();
  result.contents = (title + "\r" + arr.join("\r"));
  result.top = 700;
  result.left = 400;
  redraw();
}

function isHidden(item) {
  if (item.hasOwnProperty("hidden") && item.hidden == true) {
    return true;
  }
  if (item.hasOwnProperty("visible") && item.visible == false) {
    return true;
  }
  var result = false;
  var prnt = item.parent;
  switch (prnt.typename) {
    case "GroupItem":
      result = isHidden(prnt);
      break;
    case "Layer":
      result = isHidden(prnt);
      break;
    default:
      break;
  }
  return result;
}

function getEditableLayer(doc) {
  var aLay = doc.activeLayer;
  if (aLay.visible && !aLay.locked) return aLay;
  for (var i = 0, len = doc.layers.length; i < len; i++) {
    var curLay = doc.layers[i];
    if (curLay.visible && !curLay.locked) {
      doc.activeLayer = curLay;
      return curLay;
    }
  }
  doc.layers[0].visible = true
  doc.layers[0].locked = false;
  doc.activeLayer = doc.layers[0];
  return doc.layers[0];
}

main();

 

symbols.pngexpand image

Translate
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
New Here ,
Oct 13, 2023 Oct 13, 2023
LATEST

You're my hero! Thank you very much. Works a charm.

Translate
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