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

SYMBOLS COUNT TABLE

New Here ,
Jun 04, 2018 Jun 04, 2018

Copy link to clipboard

Copied

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

TOPICS
Scripting

Views

2.0K

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

Votes

Translate

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
...

Votes

Translate

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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 !

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

Copy link to clipboard

Copied

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.png

Screen Shot 2020-07-10 at 9.51.03 AM.png

 

thank you!

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

Copy link to clipboard

Copied

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?

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

Copy link to clipboard

Copied

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. 

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

Thank you so much, that worked! 

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

Is there a mac version of this?

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

Yes! That worked!

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

Copy link to clipboard

Copied

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 

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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.png

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

Copy link to clipboard

Copied

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

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

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]++;
}

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

Copy link to clipboard

Copied

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

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

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.png

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

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 🙂

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

function main() {
  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 + " : " + db[prop]);
  }

  var lay = getEditableLayer(doc);
  var result = lay.textFrames.add();
  result.contents = ("Result:\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.png

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

Copy link to clipboard

Copied

LATEST

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

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