19 Replies Latest reply on Sep 5, 2017 2:19 AM by maxham12

    Creating Symbols from Layers

    Natesroom1 Level 1

      Is there a way to do this? Is there a script out there that can create individual Symbols from individual layers?

       

      EDIT: I pasted this in the wrong forum so i moved it over here.

        • 1. Re: Creating Symbols from Layers
          Muppet Mark Level 5

          Yes it can be done… I've done this in past scripts for web usage ( makes them load quicker or so I was informed )

           

          Make a new symbol from the page items, delete them then place and position the symbol…

          • 2. Re: Creating Symbols from Layers
            Natesroom1 Level 1

            Ok.. i dont know how to script at all so would there possibly be a link to a script that i can run and convert every layer to a symbol?

             

            Or a script to convert EPS file in a folder into symbols?

            • 3. Re: Creating Symbols from Layers
              Natesroom1 Level 1

              ok as i've been researching i see Scripting reference has Layers and Symbol items

               

              and it seems i could say layers.pageitems or layer.pathitems

               

              is that correct?

              • 4. Re: Creating Symbols from Layers
                Natesroom1 Level 1

                // script.name = turnActiveLayerIntoSymbol.jsx;
                // script.description = creates a symbol out of all pageItems in the active layer;
                // script.required = an open doc with at least one pageItem;
                // script.parent = Carlos Canto // 3/28/11;
                // script.elegant = false;

                var doc =app.activeDocument;
                var layer = doc.activeLayer;
                var grp = layer.groupItems.add(); // add a group

                for (i=layer.pageItems.length-1; i>=1 ; i--) // loop backwards
                    {
                        layer.pageItems[i].moveToBeginning(grp); // add each pageItem to the group
                     }

                doc.symbols.add(grp);

                 

                 

                Carlos wrote this script and it does almost everything i was looking for... is there a way to add a loop or a repeat to do it to every layer in the document til its done..

                • 5. Re: Creating Symbols from Layers
                  Muppet Mark Level 5

                  Can you explain further what you want this to do… Most of the time when Im asked to script AI with symbols its for web usage… Do you just want symbols creating and adding to the symbols palette of a document or do you need symbols creating from layer content then replacing the layer content with symbol instances? Just some more background info would help…

                   

                  Edit:

                   

                  OK so it would appear that replacing content is not what you wanted… Just symbols… You just need to add a second loop if that is the case…

                  • 6. Re: Creating Symbols from Layers
                    Natesroom1 Level 1

                    Yes basically i have 300 or more signs that i use for more then one customer i wanted to create a symbol library. so i have already used the script "distributetolayers" so all the signs are on individual layers and i wanted to run a script that would create a symbol from every layer.

                     

                    The above script does exactly what i want but it stops after doing the active layer (thats probably because of var layer = doc.activeLayer;) line item.

                     

                    I want it to go through all 300 layers creat a symbol library and then i will save that library.

                    • 7. Re: Creating Symbols from Layers
                      Natesroom1 Level 1

                      so how do i add a second loop?

                      • 8. Re: Creating Symbols from Layers
                        Muppet Mark Level 5

                        OK, I didn't bother to test this so let me know…

                         

                         

                        var doc = app.activeDocument;
                        
                        var lays = doc.layers;
                        
                        for ( var i = 0; i < lays.length; i++ ) {
                        
                                  var grp = lays[i].groupItems.add();
                        
                                  var  items = lays[i].pageItems;
                        
                                  for ( var j = items.length-1; j >= 1 ; j-- ) {
                        
                                           items[j].moveToBeginning( grp );
                        
                                  };
                        
                                  doc.symbols.add( grp );
                        
                        };
                        
                        
                        • 9. Re: Creating Symbols from Layers
                          Natesroom1 Level 1

                          it gives me

                           

                          Error 2 Items is Undefined

                          Line 13

                          ->                   items[j].movetoBeginning(

                          grp);

                           

                          I'm not sure what that means

                          • 10. Re: Creating Symbols from Layers
                            Muppet Mark Level 5

                            Do you know I just posted and as I did I thought moveToBeginning wheres thats come from…?

                             

                            var doc = app.activeDocument;
                            
                            var lays = doc.layers;
                            
                            for ( var i = 0; i < lays.length; i++ ) {
                            
                                      var grp = lays[i].groupItems.add();
                            
                                      var items = lays[i].pageItems;
                            
                                      for ( var j = items.length-1; j > 0; j-- ) {
                            
                                                items[j].move( grp, ElementPlacement.PLACEATBEGINNING );
                            
                                      };
                            
                                      doc.symbols.add( grp );
                            
                            };
                            
                            • 11. Re: Creating Symbols from Layers
                              Natesroom1 Level 1

                              I really want to know how to do this! Can you add a Handle to ignore Hidden or Locked Layers?

                              • 12. Re: Creating Symbols from Layers
                                Muppet Mark Level 5

                                Of cause… Although I think Carlos is having a ( moment ) due to the lack of CS6 improvements… Started making his own…

                                 

                                Whats hidded or locked though the layers themselves or the content?

                                • 13. Re: Creating Symbols from Layers
                                  Natesroom1 Level 1

                                  The layers themselves

                                  • 14. Re: Creating Symbols from Layers
                                    Muppet Mark Level 5

                                    Again I didn't test this here…

                                     

                                    var doc = app.activeDocument;
                                    
                                    var lays = doc.layers;
                                    
                                    for ( var i = 0; i < lays.length; i++ ) {
                                      
                                              if ( lays[i].locked != false || lays[i].visible != false ) {
                                    
                                                        var grp = lays[i].groupItems.add();
                                               
                                                        var items = lays[i].pageItems;
                                               
                                                        for ( var j = items.length-1; j > 0; j-- ) {
                                               
                                                                  items[j].move( grp, ElementPlacement.PLACEATBEGINNING );
                                               
                                                        };
                                               
                                                        doc.symbols.add( grp );
                                      
                                              };
                                    
                                    };
                                    
                                    
                                    • 15. Re: Creating Symbols from Layers
                                      CarlosCanto Adobe Community Professional & MVP

                                      Hi Mark, thanks for taking care of this while I was having "my moment" ...I'm still not over it yet.

                                       

                                      moveToBeginning wheres thats come from…?

                                       

                                      almost totally undocumented, one reference on page 16 in CS4 Reference (page 15 in CS5)....works fine here on Windoze.

                                      • 16. Re: Creating Symbols from Layers
                                        Muppet Mark Level 5

                                        Carlos, Im going to take a look at that… Do you know I have a script sample created by someone else that uses similar syntax… And I've thought before now where are these commands their using come from… I thought it may derive from earlier versions of JavaScript in AI.

                                        • 17. Re: Creating Symbols from Layers
                                          maxham12

                                          Who knows how to make the script create dynamic symbols by default, rather than static?

                                           

                                          Maybe someone knows the way how to turn all static symbols into dynamic at once?

                                          • 18. Re: Creating Symbols from Layers
                                            CarlosCanto Adobe Community Professional & MVP

                                            Manually the default type of symbol is dynamic, so record and action to add a symbol, run it with a  script.

                                            • 19. Re: Creating Symbols from Layers
                                              maxham12 Level 1

                                              Whatever I do, this script creates static characters.