Skip navigation
Currently Being Moderated

looping through collection of symbols and populating a drop down on a form EXTENDSCRIPT

Apr 13, 2012 11:25 AM

Tags: #illustrator #cs5 #dropdown #form #loop #place #symbols

Hello everyone-


I got a question.  Would it be possible to run a script that would loop through a collection of symbols in a defined library and populate a drop down with the available symbols. My goal is to be able to open Illustrator, and when I run the script the dropdown is populated with all available symbols(text is fine) in a defined library that I can then select and place on the artboard. Any help would be appreciated.


thanks in advance!

  • Currently Being Moderated
    Apr 13, 2012 11:36 AM   in reply to duhwellhuh

    Im ok with lines 0 && 4 but there's an encoding issue with all in between…

    Mark as:
  • Currently Being Moderated
    Apr 13, 2012 1:14 PM   in reply to duhwellhuh

    Don't mark that as helpful is wasn't in the slightest… I was joking with you… What I meant was I can understand…


    Hello everyone and thanks in advance!


    what I don't get/follow is your description of the question… Where is defined library of symbols are the available symbols in the doc… Just trying to create the mental picture of what you are tring to acheive?

    Mark as:
  • Currently Being Moderated
    Apr 14, 2012 2:27 AM   in reply to duhwellhuh

    Ok thats a little clearer this time around… I will start with the bad news that I don't think it can be done… Can script create/populate dropdown lists on the fly well yes… that part would not be the problem… The issue that you are going to hit is AI's limitations… So far I have found NOTHING that will allow you load colors ( not even from color books ). To get colors, graphic styles, patterns, symbols etc. into an open document you have to open another document apply them to a page item then duplicate the object from one doc to the other thus bringing it's style attributes with it… What AI does now have but I've found to be useless ( well for me it is ). You can have your script open files as libraries you will get you lists in the GUI but script can't access these ( well thats what I find ). So my thoughts are the closest you will get is script opening multi-libraries for you… and you can drag n drop yourself? Sorry about that is frustrating I know… but then much of AI scripting is…

    Mark as:
  • Currently Being Moderated
    Apr 14, 2012 5:56 AM   in reply to duhwellhuh

    ScriptUI will let you create a drop down list of any array of items you like it's just a meaningless list… Your script has to make the relative association what to do when selected… You have NO scripting access to a symbol in a library ( it's just an open window/palette ) the elements do not belong to either the app or the doc… You have full access to all the open document items… Here is a picture that may better explian…


    The one on the left is the symbols in/available to my open document… I can use all these in script…

    The one on the right are the symbols of opening a library… I can't access these by script… There is ONLY document.symbols and NO app.symbols


    Until they have been copied from right palette into left palette you can't use them ( and you can only do that in the GUI )


    Screen shot 2012-04-14 at 13.47.28.png

    Mark as:
  • Currently Being Moderated
    Apr 14, 2012 9:01 AM   in reply to duhwellhuh

    An AI template file containing all your symbols is fine… That will just be doc.symbols how you chop up that array into sub arrays would be down to you… I don't see how this is going to be any improvement over the symbol scrolling at the bottom of the library palette… See the back & forth arrows in the snapshot… I can jump very quickly between sets of symbols here…


    Screen shot 2012-04-14 at 16.57.51.png

    Mark as:
  • Currently Being Moderated
    Apr 14, 2012 9:29 AM   in reply to duhwellhuh

    A quick hash so use esc key to get rid of it…

    #target illustrator
    var doc = app.activeDocument;
    var syms = Array();
    var count = doc.symbols.length;
    for ( var i = 0; i < count; i++ )  {
              syms.push( doc.symbols[i].name );
    var win = new Window( 'dialog', 'A drop down list of symbols' );
    win.add( 'dropdownlist', undefined, syms );
    Mark as:
  • Currently Being Moderated
    Apr 14, 2012 12:13 PM   in reply to duhwellhuh

    Yes what you need to remember is collections like pathItems although similar in some repects are not actually arrays… So your dropdownlist wants a javascript array as parameter so I created an empty one then using the array method push placed each symbol's name at the end of the array. I hope thats making sence? I could NOT pass the collection pathItems it wouldn't be accepted… ID has better methods which avoid the need to loop but thats another story… Hope it helps you non the less…

    Mark as:
  • Currently Being Moderated
    Apr 14, 2012 1:12 PM   in reply to duhwellhuh

    I'll not hold my breath… AI isn't from the same planet… it orbits closer to Quark…

    Mark as:
  • Currently Being Moderated
    Apr 28, 2012 1:42 PM   in reply to Muppet Mark

    Hi everybody,


    I add the same issue... a lot and heavy symbols I cannot put on my template (too heavy to load...) so, I proceed in to step :

    1) Open my template

    2) Open the file with a specific library

    3) Select a symbol

    4) copy it

    5) Close the specific library

    6) past on the template (as soon as you do it, the symbol will be added into your local library

    7) clear de Clipboard

    8) remove selected object due to the fact the symbol is still "selected" when you past it


    Now you're ready to work with your imported symbol


    If somebody is interested I can send an short VB example.


    Kind Regards.



    Mark as:
  • Currently Being Moderated
    Apr 30, 2012 7:14 AM   in reply to duhwellhuh



    Dim appref As New Illustrator.Application
    Dim docRef As Illustrator.Document                                                                         'The work document
    Dim docToAdd As Illustrator.Document                                                                    'The document which contain the symbol's library 

    Dim pathArt As Object
    Dim ItemSymbol As Object
    Dim itemSymbolref As Illustrator.Symbol
    Dim artObject As Variant


    appref.Open ("C:\.....")
    Set docRef = appref.ActiveDocument                                                                         'Assign docRef to your work document

    appref.Open ("C:\")
    Set docToAdd = appref.ActiveDocument                                                                     'Assign docToAdd to your symbol document


    Set symbolref = appref.ActiveDocument.Symbols(Symbol_Name)                                'Assign symbol ref the symbol you're looking for

    Set itemref = appref.ActiveDocument.SymbolItems.Add(symbolref)                               'Copy it on the current active page


    itemref.Selected = True                                                                                              'select it
    docToAdd.Copy                                                                                                         'add it to your clibboard

    docToAdd.close (aiDoNotSaveChanges)                                                                      'Close the library, without changing anything


    appref.ActiveDocument.Paste                                                                                     'Paste the clipboard on your work document

                             'As soon as you paste the symbol, it will be added in the document symbol library


    Clipboard_Clear                                                                                                         'See below why...

    SelectedObjects =appref.ActiveDocuments.selection                                                    ' Select the symbol you past


                             ' The loop is not necessary if you have only one thing selected

    For Each artObject In selectedObjects


                             ' Cleanup your pointers

    Set artObject = Nothing
    Set pathArt = Nothing
    Set docToAdd = Nothing

    [....] Continue your script on your working document


    Set docRef = Nothing               'after closing your working doc...


    Remark on clipboard_clear : If you don't do it, the risk is to accumulate plenty other things you don't want...


    Public Function ClipBoard_Clear()
      Call OpenClipboard(0&)
      Call EmptyClipboard
      Call CloseClipboard
    End Function






    Public Declare PtrSafe Function OpenClipboard Lib "user32" (ByVal hWnd As Long) As Long
    Public Declare PtrSafe Function CloseClipboard Lib "user32" () As Long
    Public Declare PtrSafe Function EmptyClipboard Lib "user32" () As Long



    be careful I use the PtrSafe pointer due to the fact I'm working in x64 architecture
    in x86 it will be

    Public Declare Function OpenClipboard Lib "user32" (ByVal hWnd As Long) As Long
    Public Declare Function CloseClipboard Lib "user32" () As Long
    Public Declare Function EmptyClipboard Lib "user32" () As Long


    Regards to all



    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points