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!
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--){
Copy link to clipboard
Copied
Aah! Of course, that makes sense. Thank you, Carlos!
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
/*
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();
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
/*
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();
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 )
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
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.
Is it something I am doing in my symbols window incorrectly? I ran it just last week and it was working fine...
Copy link to clipboard
Copied
Are there unvisible or locked objects/layers in your document? (Screenshot?)
Copy link to clipboard
Copied
Yes! Wow that fixed it. Thank you so much!
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
Copy link to clipboard
Copied
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 items
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
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.
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.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
@rafac92111371
I'll send a PM