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

Scanning a document for symbol names

New Here ,
Feb 18, 2009 Feb 18, 2009
I'm about to undertake a project writing a script that will scan through an Illustrator file and produce a list of the symbols used within the document.

While I've scripted for web before, I haven't yet scripted for a program such as Illustrator, so I wanted to make sure that this is a project that is even possible, and if there are any tips anyone could provide me for areas to look at that will help, or if there are any specific bits of script that will help me on my way?

Thanks for any help

Dan.
TOPICS
Scripting
1.9K
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
Adobe
Advocate ,
Feb 18, 2009 Feb 18, 2009
Should be fairly easy. You can get the list of symbolItems for the document, and get the name property for each one. (provided they have names)

This will show the name of symbol Item 1:

alert (app.activeDocument.symbolItems[1].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 ,
Feb 19, 2009 Feb 19, 2009
Hey, this bit of script is what i'm using for that...

get name of every symbol of document 1

i've got a question for you or anybody else... how can i place a symbol instance using the symbols name... right now i can only place a symbol using the generic "symbol 1 of document 1" syntax...

i need to be able to place each symbol by name... any suggestions?..
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 ,
Feb 19, 2009 Feb 19, 2009
oops, i forgot to check what type of script you're using... i'm using applescript... i'm assuming you are not since the other person gave you that other syntax...
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 ,
Feb 19, 2009 Feb 19, 2009
Adapted from the AppleScript guide

tell application "Adobe Illustrator"
activate
make new symbol item in document 1 with properties ¬
{symbol:symbol "USGS" of document 1, position:{100, 200}}
end tell

where the name in quotes is the name of the symbol.
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 ,
Feb 19, 2009 Feb 19, 2009
From what I've worked on so far, I've got a bit of code very similar to yours, Typeset. I originally was doing the same thing but by setting selection to all symbol items of the current document, but your way is more concise so I've since amended to

tell application "Illustrator CS"
get name of every symbol item of current document
end tell

This script works, however, the symbol item names are coming back blank. Are they not the same as the name for the symbol item? Is this something that needs to be set manually and seperately?

Thanks - Dan.
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 ,
Feb 19, 2009 Feb 19, 2009
A symbol has a name; a symbol item doesn't.
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 ,
Feb 19, 2009 Feb 19, 2009
Hmm, fair enough, although, it seems as though it does (perhaps this is a freak occurrence or something - I don't like to dispute people who are more experienced with a subject, particularly if they are well up on the theory behind it!). I've just manually entered names for my symbol items in the layers panel, and then run the same script and it did return the names that I'd entered.

The only problem here is that, the whole point of the script is to automatically generate a list of the symbols used, so having to manually enter the names every time renders the script redundant.

I've tried a few different combinations now, but I'm not having much luck getting the script to return the Symbol Names of the Symbol Items in the document.

If anyone has any suggestions, I'm all ears.

Thanks - Dan
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 ,
Feb 19, 2009 Feb 19, 2009
Try this (also modified from the AppleScript guide)

tell application "Adobe Illustrator"
set symNames to ""
if not (exists document 1) then error "There is no available document."
get the name of every symbol of document 1
repeat with theName in the result
set symNames to symNames & theName & return
end repeat
display dialog symNames
end tell
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 ,
Feb 19, 2009 Feb 19, 2009
Hm, seems as though this is going somewhere, however, that code again displays all the symbols in the library in the dialog box. I looked into changing the variable for the dialog from symNames to theName, but (as I expected, in all honesty), this only displays 1 of the symbols, and again this just picks from the library.

Is it going to be best looking at this as 2 tells, a first one to tell Illustrator to name the symbol items, and then a 2nd one for displaying dialog?

Cheers
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
Advocate ,
Feb 19, 2009 Feb 19, 2009
What you want to do is get the symbol items in the document, then loop through them getting the name of the symbol for that symbol item.

tell application "Adobe Illustrator"
set symNames to ""
if not (exists document 1) then error "There is no available document."
set theSymbolItems to every symbol item of document 1
repeat with theSymbolItem in theSymbolItems
set symNames to symNames & (name of symbol of theSymbolItem) & return
end repeat
display dialog symNames
end tell

This will give you a list of only the items that are used in the document (which is why I used Symbol Item instead of Symbol). It will include duplicates so you need to check to see if the symbol was already included in the list if you want to filter out dupes.
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 ,
Feb 20, 2009 Feb 20, 2009
Filtered.

tell application "Adobe Illustrator"
set Symbol_Names to {}
if not (exists document 1) then error "There is no available document."
set Symbol_Item_List to name of symbol of every symbol item of document 1
repeat with i from 1 to count of Symbol_Item_List
if Symbol_Names does not contain item i of Symbol_Item_List then
set end of Symbol_Names to item i of Symbol_Item_List
end if
end repeat
display dialog (my List_to_String(Symbol_Names)) giving up after 3
end tell
--
on List_to_String(The_List)
set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return}
set The_List to items of The_List as string
set AppleScript's text item delimiters to ASTID
return The_List
end List_to_String
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
Advocate ,
Feb 20, 2009 Feb 20, 2009
You'll need to error trap the line

set Symbol_Item_List to name of symbol of every symbol item of document 1

If there are no symbol items used in the document, it will not run properly. Trying to get the properties of non-existent items will cause an error.
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 ,
Feb 20, 2009 Feb 20, 2009
Doh! forgot about that This should be nearer the mark.

tell application "Adobe Illustrator"
if not (exists document 1) then error "There is no available document."
set Symbol_Names to {}
set Symbol_Item_List to {}
try
set Symbol_Item_List to name of symbol of every symbol item of document 1
end try
if Symbol_Item_List ≠ {} then
repeat with i from 1 to count of Symbol_Item_List
if Symbol_Names does not contain item i of Symbol_Item_List then
set end of Symbol_Names to item i of Symbol_Item_List
end if
end repeat
display dialog (my List_to_String(Symbol_Names)) giving up after 3
else
display dialog "There are no symbol instanes in this doc" giving up after 3
end if
end tell
--
on List_to_String(The_List)
set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return}
set The_List to items of The_List as string
set AppleScript's text item delimiters to ASTID
return The_List
end List_to_String
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 11, 2009 Mar 11, 2009
I've been testing and using the excellent bit of coded that was put up by Mark, but I've come across a bug (well, not strictly a bug, just where it works differently to my needs).

Anyway, if there are 2 instances of the same symbol, they only appear in the list once. Ideally, I need to display them all, or create a numbering system. I was thinking of perhaps scanning back through the list as the script works, and if there are any instances with the same name, to add an integer to the end of the name...

What kind of code should I be looking at for this? Are there any good references for it, or areas of the previous code anyone could point me to?

Thanks - Dan.
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
Advocate ,
Mar 11, 2009 Mar 11, 2009
LATEST
Although I'm not sure why you want the same item listed multiple times, I believe you could change the lines:

if Symbol_Names does not contain item i of Symbol_Item_List then
set end of Symbol_Names to item i of Symbol_Item_List
end if

to:

set Symbol_Name to item i of Symbol_Item_List
set Symbol_Name_Test to Symbol_Name
set i to 0
repeat while Symbol_Names contains Symbol_Name_Test
set i to i + 1
set Symbol_name_Test to (Symbol_Name & "-" & i) as string
end repeat
set end of Symbol_Names to Symbol_Name_Test

This will add a number to the end of the repeated names. If you just want the names repeated without the number, just remove the "If" and "End If" lines from the original 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