19 Replies Latest reply: Apr 30, 2012 7:15 AM by duhwellhuh RSS

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

    duhwellhuh Community Member

      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!

        • 1. Re: looping through collection of symbols and populating a drop down on a form EXTENDSCRIPT
          Muppet Mark Community Member

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

          • 2. Re: looping through collection of symbols and populating a drop down on a form EXTENDSCRIPT
            duhwellhuh Community Member

            So it's not possible?  What do you mean by encoding issue?

            • 3. Re: looping through collection of symbols and populating a drop down on a form EXTENDSCRIPT
              Muppet Mark Community Member

              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?

              • 4. Re: looping through collection of symbols and populating a drop down on a form EXTENDSCRIPT
                duhwellhuh Community Member

                Oh, ok. I figured that it was possible that it could have been an encoding issue so I marked it helpful. Sorry to be confusing.

                 

                Ok– What I want to do is this:

                 

                Let’s say I setup 20 symbols in a file and saved them as a user defined library called “Zippers”. I could manually go in, locate, grab the symbol and drop it on the artboard, but what I want to do is to have a script loop through “Zippers” and populate the drop down with the symbol names in that collection. That way I could initiate the dropdown, select the name of the symbol I want and then on the click of a button dump the symbol on the artboard.

                 

                It does sound like it would be just as easy to manually do this, but I anticipate this library becoming large. I also plan on having multiple drop downs with each drop down accessing other libraries with names like “VZB” and “POLYBAG”, thus pulling in other symbols simultaneously on the click of a button.

                 

                I would hope that each time I ran this, that any new symbols added to the collection since the last run would populate into the dropdown as well. In my experience, I’ve only been able to add dropdown items directly through hard coding them in script. I want the script to read through the collection and populate the dropdown with what it finds without having to hardcode them.

                 

                I hope this makes sense, thanks.

                • 5. Re: looping through collection of symbols and populating a drop down on a form EXTENDSCRIPT
                  Muppet Mark Community Member

                  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…

                  • 6. Re: looping through collection of symbols and populating a drop down on a form EXTENDSCRIPT
                    duhwellhuh Community Member

                    That is frustrating. So let me get this straight:

                     

                    Illustrator scripting won't allow me to populate a dropdown with the names of the symbols in a given user defined library.

                    You said scripting could populate drop downs on the fly. In what ways could this be done or be useful if you can't access libraries of colors,graphic styles,.etc...or are you saying that it's

                    possible in script but not in Illustrator?

                     

                    This is confusing to me because you can add symbols to the artboard by accessing part of a library and redrawing them, so is the limitation populating the dropdown with the symbol file names or in accessing symbols that aren't in the default symbol location in the GUI of a new file? This may be confusing, I couldn't think of any other way to put it.

                     

                    Your help is always appreciated and sorry for being confused.

                    • 7. Re: looping through collection of symbols and populating a drop down on a form EXTENDSCRIPT
                      Muppet Mark Community Member

                      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

                      • 8. Re: looping through collection of symbols and populating a drop down on a form EXTENDSCRIPT
                        duhwellhuh Community Member

                        ok, thanks, I think I'm starting to follow you.

                        So if I was to create a template file, place all of the symbols that I would need in the document's symbol library, could I populate the drop down with those? From your left example above, could the names of the symbols be populated in the drop down list as those are accessible in script and be chosen and drawn on the artboard on a button click?

                         

                        If that's the case, couldn't I use wild cards and if statements to feel each separate dialog?

                         

                        For example-

                         

                        One dropdown would be linked to symbols whose names began with "Zip*" and the second would be linked to symbols whose names began with "POLY*". These wouldn't be in separate libraries but they would be in the one accessible throught script in the active document.

                         

                        Is this doable, if not I'll give up and call it a day!

                        • 9. Re: looping through collection of symbols and populating a drop down on a form EXTENDSCRIPT
                          Muppet Mark Community Member

                          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

                          • 10. Re: looping through collection of symbols and populating a drop down on a form EXTENDSCRIPT
                            duhwellhuh Community Member

                            Alright Mark, I guess you are right. It does work the same way. My idea would only knock off a minute or two anyways. I was just trying to make it easier.

                             

                            Just to know, how would you list the collection of symbols to the drop down box on the fly or any collection for that matter?

                            • 11. Re: looping through collection of symbols and populating a drop down on a form EXTENDSCRIPT
                              Muppet Mark Community Member

                              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 );
                              
                              win.center();
                              
                              win.show();
                              
                              • 12. Re: looping through collection of symbols and populating a drop down on a form EXTENDSCRIPT
                                duhwellhuh Community Member

                                Sweet, thanks Mark! I appreciate your time and effort.  It actually looks less complicated then I thought.

                                 

                                So ".push" is used to get the name as text in the array?

                                • 13. Re: looping through collection of symbols and populating a drop down on a form EXTENDSCRIPT
                                  Muppet Mark Community Member

                                  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…

                                  • 14. Re: looping through collection of symbols and populating a drop down on a form EXTENDSCRIPT
                                    duhwellhuh Community Member

                                    As always a big help! It does make sense, but until I get more experience, I'll still struggle. As soon as I think I'm getting a grasp, I see a technique that I've never heard of.

                                     

                                    It seems from your post and other posts I've read that ID is far more superior than Illustrator in the scripting sense. I would hope that CS6 would take some of these issues to heart, but we'll see about that.

                                     

                                    thanks again!

                                    • 15. Re: looping through collection of symbols and populating a drop down on a form EXTENDSCRIPT
                                      Muppet Mark Community Member

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

                                      • 16. Re: looping through collection of symbols and populating a drop down on a form EXTENDSCRIPT
                                        mitch_ch

                                        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.

                                         

                                        Michel

                                        • 18. Re: looping through collection of symbols and populating a drop down on a form EXTENDSCRIPT
                                          mitch_ch Community Member

                                          So...

                                           

                                          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:\..... workDoc.ai")
                                          Set docRef = appref.ActiveDocument                                                                         'Assign docRef to your work document


                                          appref.Open ("C:\......symbolDoc.ai")
                                          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
                                              artObject.Delete
                                          Next

                                           

                                                                   ' 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

                                           

                                           

                                          With

                                           

                                           

                                          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

                                           

                                          Michel

                                          • 19. Re: looping through collection of symbols and populating a drop down on a form EXTENDSCRIPT
                                            duhwellhuh Community Member

                                            Thanks for the note at the bottom as my structure is 32bit. Sweet, thanks a lot!