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

Looking for "Replace with Symbol" script

New Here ,
Dec 19, 2011 Dec 19, 2011

Copy link to clipboard

Copied

So I am trying to replace gps points with a symbol I have created. I have found blogs referencing a script that can replace selected items with symbols saved in the symbols panel, but I can't seem to find the actual script! If anyone knows where I can find JET_ReplaceWithSymbol.jsx or any other script that can do the same function, it would be greatly appreciated!

TOPICS
Scripting

Views

15.3K

Translate

Translate

Report

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
Community Expert ,
Mar 31, 2019 Mar 31, 2019

Copy link to clipboard

Copied

cool, thanks for sharing details.

every time you remove an object the indexes get remade. ie if you start with 2 objects, your loop will only run once. pathItem[0] will get processed, but after you remove it, pathItem[1] will move down to pathItem[0]. Your loop should call second pathItem but your array will only have 1 item at that point, so your for-loop will end.

to fix, run your loop backwards, starting with the last pathItem, so removing it will have no negative effect in the remaining items indexes.

for(i=docRef.pathItems.length-1; i>=0 ;i--){

Votes

Translate

Translate

Report

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
LEGEND ,
Apr 01, 2019 Apr 01, 2019

Copy link to clipboard

Copied

Aah! Of course, that makes sense. Thank you, Carlos!

Votes

Translate

Translate

Report

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
Advocate ,
Apr 20, 2023 Apr 20, 2023

Copy link to clipboard

Copied

You can also enable the 9-scale option in the symbol, that way, if it has rounded corners, they dont stretch.

 

PS here's my edit, its prompts the user for a name. So you dont need to edit the JSX file all the time
dialog promptdialog prompt

 

 

/*
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 symbolName=prompt("Enter the name of the Symbol you want to replace each selected object","Enter Name");

for(i=0;i<docRef.selection.length;i++){
    var currObj=docRef.selection[i];
    try {
        var rotationTag = currObj.tags[0];
    } catch (e){
        var rotationTag = { name: "build", value:Number(0) };
    }
    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]);
    // var currInstance=docRef.symbolItems.add(docRef.symbols[7-1]);
    // var currInstance=docRef.symbols.getByName("cross");
    // var currInstance=docRef.symbols.add(docRef.symbols["cross"]);
    try{
        sym = docRef.symbols.getByName(symbolName)
    } catch (e) {
        // alert(e)
        alert("Symbol "+symbolName+" can not be found")
        break
    }
    var currInstance=docRef.symbolItems.add(sym)
    currInstance.width*=currHeight/currInstance.height;
    currInstance.height=currHeight;
    currInstance.left=currLeft;
    currInstance.top=currTop;
    currInstance.selected=true;
    currInstance.rotate(rotationTag.value * 180 / Math.PI, true)
    currObj.remove();
}
redraw();

 

 

Votes

Translate

Translate

Report

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
Advocate ,
Apr 20, 2023 Apr 20, 2023

Copy link to clipboard

Copied

ive done some more edits. It now also adjsuts the bounding box. So the rotation is applied to that as well. That was driving me nuts

 

I cant show it because i cant screengrab that. Basically doing the rotation through keeps the boundingbox at 0.

EDIT

I made a screen recoding so i can show it, the last script is this updated one below
preview of updated scriptpreview of updated script

/*
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 symbolName=prompt("Enter the name of the Symbol you want to replace each selected object","Enter Name");

for(i=0;i<docRef.selection.length;i++){
    var currObj=docRef.selection[i];
    try {
        var rotationTag = currObj.tags[0];
    } catch (e){
        // 
        var rotationTag = { name: "build", value:Number(0) };
    }
    var currLeft=currObj.left;
    var currTop=currObj.top;
    var currWidth=currObj.width;
    var currHeight=currObj.height;

    try{
        sym = docRef.symbols.getByName(symbolName)
        // sym = docRef.symbols.getByName(symbolName)
    } catch (e) {
        // alert(e)
        alert("Symbol "+symbolName+" can not be found")
        // alert(`This is ${symbolName} times easier!`)
        break
    }
    var currInstance=docRef.symbolItems.add(sym)
    currInstance.width*=currHeight/currInstance.height;
    currInstance.height=currHeight;
    currInstance.left=currLeft;
    currInstance.top=currTop;
    currInstance.selected=true;
    // add Bounding rotation aswell > this was a bit hard to find
    tags = currInstance.tags;
    tags.add()
    currInstance.tags[0].name = "BBAccumRotation"
    var pi = Math.PI;
    // var degrees * (pi/180);
    // ob.tags[0].value = (10* 180 / Math.PI)
    currInstance.tags[0].value = rotationTag.value //10* (pi/180);
    currInstance.rotate(rotationTag.value * 180 / Math.PI, true)
    currObj.remove();
}
redraw();

Votes

Translate

Translate

Report

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 ,
Dec 19, 2011 Dec 19, 2011

Copy link to clipboard

Copied

This John Wundes script should be do the same:

http://www.wundes.com/JS4AI/copyToMultipleObjects.js

Unfortunately the Jet-scripts on his (--> http://www.illustrationetc.com/AI_Javascripts/) old site are not longer available. Maybe someone knows the current page. (Perhaps Jet himself  )

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Hi everyone,

I used Muppet Mark script:

It works really well but the script remove my layers name. I have a world map with pin points for each city separated by layers.

Some help? Muppet Mark

Votes

Translate

Translate

Report

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 ,
Jun 13, 2019 Jun 13, 2019

Copy link to clipboard

Copied

Hello! I am having difficulty running the script. I am a n00bie here so hopefully this is a quick fix. I am using JET's script and when I try to run it in Illustrator it says there is a problem with line 15 of the code.

Screen Shot 2019-06-13 at 1.31.21 PM.png

Is it something I am doing in my symbols window incorrectly? I ran it just last week and it was working fine...

Votes

Translate

Translate

Report

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 ,
Jun 13, 2019 Jun 13, 2019

Copy link to clipboard

Copied

Are there unvisible or locked objects/layers in your document? (Screenshot?)

Votes

Translate

Translate

Report

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 ,
Jun 13, 2019 Jun 13, 2019

Copy link to clipboard

Copied

Yes! Wow that fixed it. Thank you so much!

Votes

Translate

Translate

Report

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 ,
Dec 21, 2023 Dec 21, 2023

Copy link to clipboard

Copied

Hi guys. This plugin is very good, but does anyone know if when you replace the object to the symbol in your library, the size of the already created symbol could be maintained and not adapt to the size of the previously selected object?

Thanks a lot

Votes

Translate

Translate

Report

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
Advocate ,
Dec 21, 2023 Dec 21, 2023

Copy link to clipboard

Copied

@rafac92111371 

You need to select all the instance used, than select the new symbol on the panel and from the context menu (small menu top right) > choose replace.

 

It will replace all selected items and keep rotation and size etc etc

Im not sure you can replace but keep the size of the new selected item. If you commented out the part about scale it should work as you want but probably get misplaced, as its being placed by top and left. Meaning the symbol is not centered on the selected itemscomment out these lines so it keeps the size of the symbolcomment out these lines so it keeps the size of the symbol

Check this video, when you comment  out those lines. It will keep the size of the pathItems selected and will also do the rotation properly. The second run i show is how the other version works which i adjusted
Example how selected pathItems get replaced but keep size of the symbolExample how selected pathItems get replaced but keep size of the symbol

Votes

Translate

Translate

Report

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 ,
Dec 23, 2023 Dec 23, 2023

Copy link to clipboard

Copied

Thank you very much for your explanation, but it would be possible to download the pluggin to be able to comment on those lines as you show me in the image. I don't think the pluggin I have is like that.

Votes

Translate

Translate

Report

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
Advocate ,
Dec 23, 2023 Dec 23, 2023

Copy link to clipboard

Copied

I don't quite understand what you mean?

You can simply adjust the one you have. Simply "Turn off" those lines I showed you.

Votes

Translate

Translate

Report

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 ,
Dec 28, 2023 Dec 28, 2023

Copy link to clipboard

Copied

Good morning and thank you so much for your early response. Yes, but I can
see that those lines of code are not exactly the same as mine, so replacing
them gives me an error. Could you send me the full code? Thank you so much

Rafa

Votes

Translate

Translate

Report

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
Advocate ,
Dec 28, 2023 Dec 28, 2023

Copy link to clipboard

Copied

LATEST

@rafac92111371 
I'll send a PM

Votes

Translate

Translate

Report

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