Skip to main content
Participant
Jun 4, 2018 7:46 PM UTC
Answered

SYMBOLS COUNT TABLE

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

This topic is closed to new replies. Start a new post to keep the conversation going.
CarlosCanto
CarlosCantoCorrect answer
Community Expert
Jul 10, 2020 4:18 PM UTC

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

24 replies

CarlosCanto
Community Expert
Community Expert
Nov 5, 2020 6:54 PM UTC

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

Translate
Participant
Mar 8, 2023 3:01 PM UTC

Is there a mac version of this?

Translate
Larry G. Schneider
Community Expert
Community Expert
Mar 8, 2023 3:13 PM UTC

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
CarlosCanto
Community Expert
CarlosCantoCommunity ExpertCorrect answer
Community Expert
Jul 10, 2020 4:18 PM UTC

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
Known Participant
Jul 10, 2020 4:35 PM UTC

Thank you so much, that worked! 

Translate
Loic.Aigon
Legend
Jun 5, 2018 11:14 AM UTC

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
Participant
Jun 5, 2018 1:41 PM UTC

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
Known Participant
Jul 10, 2020 1:51 PM UTC

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!

Translate