Skip to main content
Participant
June 4, 2018
Answered

SYMBOLS COUNT TABLE

  • June 4, 2018
  • 3 replies
  • 3725 views

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

This topic has been closed for replies.
Correct answer CarlosCanto

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(); 

3 replies

CarlosCanto
Community Expert
Community Expert
November 5, 2020

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

Participant
March 8, 2023

Is there a mac version of this?

Jatohniedan
Participating Frequently
October 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();

 

 


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.

CarlosCanto
Community Expert
CarlosCantoCommunity ExpertCorrect answer
Community Expert
July 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(); 
Known Participant
July 10, 2020

Thank you so much, that worked! 

Loic.Aigon
Legend
June 5, 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();

Participant
June 5, 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 !

Known Participant
July 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

 

thank you!