Skip to main content
Participant
October 16, 2015
Question

Add to the JET_ReplaceWithSymbol.jsx SCript an variable to save Layer name

  • October 16, 2015
  • 2 replies
  • 1856 views

Hi guys i have a big illustrator file full of layers and I realized to late that I should have used symbols instead of object.

I found this amazing script that replace object by symbols:

  1. /*
  2. JET_ReplaceWithSymbol.jsx
  3. A Javascript for Adobe Illustrator
  4. Purpose: Replaces selected items with Instances of a Symbol from the Symbols Panel.
  5. The desired Symbol can be defined by its index number (its number of occurrance in the Panel).
  6. */ 
  7. var docRef=app.activeDocument; 
  8. var symbolNum=prompt("Enter the number of the Symbol you want to replace each selected object",1); 
  9. for(i=0;i<docRef.selection.length;i++){ 
  10.           var currObj=docRef.selection
  11.           var currLeft=currObj.left; 
  12.           var currTop=currObj.top; 
  13.           var currWidth=currObj.width; 
  14.           var currHeight=currObj.height; 
  15.           var currInstance=docRef.symbolItems.add(docRef.symbols[symbolNum-1]); 
  16.           currInstance.width*=currHeight/currInstance.height; 
  17.           currInstance.height=currHeight; 
  18.           currInstance.left=currLeft; 
  19.           currInstance.top=currTop; 
  20.           currInstance.selected=true
  21.           currObj.remove(); 
  22.           redraw(); 

My only problem is that the script rename every layer name by "new symbol", I would like to keep the names like they are.

Would you have a line for me to add to the code to change that?

I tried that:     var layernames =currentLayer.name   (failed)

Thank you

2 replies

Md_Adhom Ali8087
Participant
October 25, 2025

Hey, I need this JET_ReplaceWithSymbol

CarlosCanto
Community Expert
Community Expert
October 25, 2025

the script is right here at the top of the page, the OP posted it

Qwertyfly___
Legend
October 19, 2015

it does not rename the layers.

it just replaces the items with symbols,

and it does not keep layer structure intact.

but if it's doing what you need, then that's fine.

what you are wanting is to rename each symbol instance with the original objects name.

currInstance.name = currObj.name;

I also moved the redraw line outside the for loop.

this means you can undo (ctrl + Z) just once, instead of many times. if that makes sense.

/*

JET_ReplaceWithSymbol.jsx

A Javascript for Adobe Illustrator

Purpose: Replaces selected items with Instances of a Symbol from the Symbols Panel.

The desired Symbol can be defined by its index number (its number of occurrance in the Panel).

*/

var docRef=app.activeDocument;

var symbolNum=prompt("Enter the number of the Symbol you want to replace each selected object",1);

for(i=0;i<docRef.selection.length;i++){

          var currObj=docRef.selection;

          var currLeft=currObj.left;

          var currTop=currObj.top;

          var currWidth=currObj.width;

          var currHeight=currObj.height;

          var currInstance=docRef.symbolItems.add(docRef.symbols[symbolNum-1]);

          currInstance.width*=currHeight/currInstance.height;

          currInstance.height=currHeight;

          currInstance.left=currLeft;

          currInstance.top=currTop;

          currInstance.selected=true;

          currInstance.name = currObj.name;

          currObj.remove();

}

redraw();

Participant
October 19, 2015

Hi,

First thank you for answering my question.

Unfortunately it doesn't work, I tried few times, sometimes the layer name is staying (20%) but the layers are moved back from the sublayers.

Any other suggestions?

Regards

Participant
October 19, 2015

Hi,

The layers are still being moved but...

I put the "redraw(); inside the loop, just to try....

I select the script---> objects are replace with my symbol ---> layers are rename "new Symbols" ---> I do cmd+z ----> layers name become like they were before (strange I know) ----> shift+cmd+z -----> done (with layers at the wrong place}

....