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

Creating Symbols from Layers

Participant ,
May 10, 2012 May 10, 2012

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.

TOPICS
Scripting
5.6K
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

correct answers 1 Correct answer

Mentor , May 10, 2012 May 10, 2012

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.groupItems.add();

          var items = lays.pageItems;

          for ( var j = items.length-1; j > 0; j-- ) {

                    items.move( grp, ElementPlacement.PLACEATBEGINNING );

          };

          doc.symbols.add( grp );

};

Translate
Adobe
Mentor ,
May 10, 2012 May 10, 2012

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…

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
Participant ,
May 10, 2012 May 10, 2012

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?

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
Participant ,
May 10, 2012 May 10, 2012

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?

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
Participant ,
May 10, 2012 May 10, 2012

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

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
Mentor ,
May 10, 2012 May 10, 2012

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…

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
Participant ,
May 10, 2012 May 10, 2012

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.

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
Participant ,
May 10, 2012 May 10, 2012

so how do i add a second loop?

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
Mentor ,
May 10, 2012 May 10, 2012

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.groupItems.add();

          var  items = lays.pageItems;

          for ( var j = items.length-1; j >= 1 ; j-- ) {

                   items.moveToBeginning( grp );

          };

          doc.symbols.add( grp );

};

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
Participant ,
May 10, 2012 May 10, 2012

it gives me

Error 2 Items is Undefined

Line 13

->                   items.movetoBeginning(

grp);

I'm not sure what that means

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
Mentor ,
May 10, 2012 May 10, 2012

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.groupItems.add();

          var items = lays.pageItems;

          for ( var j = items.length-1; j > 0; j-- ) {

                    items.move( grp, ElementPlacement.PLACEATBEGINNING );

          };

          doc.symbols.add( grp );

};

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
Participant ,
May 10, 2012 May 10, 2012

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

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
Mentor ,
May 10, 2012 May 10, 2012

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?

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
Participant ,
May 10, 2012 May 10, 2012

The layers themselves

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
Mentor ,
May 10, 2012 May 10, 2012

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.locked != false || lays.visible != false ) {

                    var grp = lays.groupItems.add();

          

                    var items = lays.pageItems;

          

                    for ( var j = items.length-1; j > 0; j-- ) {

          

                              items.move( grp, ElementPlacement.PLACEATBEGINNING );

          

                    };

          

                    doc.symbols.add( grp );

 

          };

};

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 ,
May 11, 2012 May 11, 2012

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.

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
Mentor ,
May 11, 2012 May 11, 2012

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.

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
Participant ,
Oct 11, 2018 Oct 11, 2018

I think this must have worked back in 2012, but its not working now the error i get is:

Muppet Mark

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 ,
Oct 12, 2018 Oct 12, 2018

please post the script you're using and a file that's throwing the error.

thanks

carlos

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
Participant ,
Oct 12, 2018 Oct 12, 2018
  1. var doc = app.activeDocument; 
  2.  
  3. var lays = doc.layers; 
  4.  
  5. for ( var i = 0; i < lays.length; i++ ) { 
  6.    
  7.           if ( lays.locked != false || lays.visible != false ) { 
  8.  
  9.                     var grp = lays.groupItems.add(); 
  10.             
  11.                     var items = lays.pageItems; 
  12.             
  13.                     for ( var j = items.length-1; j > 0; j-- ) { 
  14.             
  15.                               items.move( grp, ElementPlacement.PLACEATBEGINNING ); 
  16.             
  17.                     }; 
  18.             
  19.                     doc.symbols.add( grp ); 
  20.    
  21.           }; 
  22.  
  23. }; 

Gives me this error

I opened 36 files each on their own artboard and i thought that this script was supposed to add them to the symbol library

EDIT: OK FIGURED OUT THAT EACH item was imported as a "placed" item... once i "embeded" the EPS Objects, then the script worked perfectly, however can i ask that the script make each symbol name the same as the layer name instead of "Symbol 1" or "symbol 2"??

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 ,
Oct 12, 2018 Oct 12, 2018

cool,

to name your symbols change line 19 to the below code and add one more line after it.

                    var mySymbol = doc.symbols.add( grp ); 

                    mySymbol.name = lays.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
Participant ,
Oct 12, 2018 Oct 12, 2018
LATEST

Carlos that worked perfectly

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
Explorer ,
Sep 04, 2017 Sep 04, 2017

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?

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 ,
Sep 04, 2017 Sep 04, 2017

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

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
Explorer ,
Sep 05, 2017 Sep 05, 2017

Whatever I do, this script creates static characters.

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