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

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

Community Beginner ,
Oct 16, 2015 Oct 16, 2015

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

TOPICS
Scripting
1.9K
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
Adobe
Guide ,
Oct 18, 2015 Oct 18, 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();

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 Beginner ,
Oct 19, 2015 Oct 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

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 Beginner ,
Oct 19, 2015 Oct 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}

....

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
Guide ,
Oct 19, 2015 Oct 19, 2015

Any chance I can see the file.

im not sure I get what your saying.

THis is script won't change your layer names.

but it will delete all selected items.

REplacing them with symbols.

all the symbols are placed in the top layer.

so it will destroy your document structure.

if you can post your file or an example it may make it clearer

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 Beginner ,
Oct 20, 2015 Oct 20, 2015

I can't share the full file due to privacy but I will make a sample as soon as I have some time soon.

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
Guide ,
Oct 20, 2015 Oct 20, 2015

once I see that it should make it clearer.

would be worth seeing 1 that is a before, and 1 that shows what you want it to be when your 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
New Here ,
Oct 25, 2025 Oct 25, 2025

Hey, I need this JET_ReplaceWithSymbol

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 25, 2025 Oct 25, 2025
LATEST

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

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