Skip navigation
Currently Being Moderated

Looking for "Replace with Symbol" script

Dec 19, 2011 11:15 AM

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!

 
Replies
  • Currently Being Moderated
    Dec 19, 2011 11:23 AM   in reply to folkmane

    Did you also post in the general forum? Jet is still a regular contributor there… although he doesn't post here in scripting a great deal these days… I will have a look if I have this I keep quite a few of Jet's scripts for reference…

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 19, 2011 11:58 AM   in reply to folkmane

    Found it… Im sure Jet won't object to me posting here… Hope it helps…

     

    /*
    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[i];
              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;
              currObj.remove();
              redraw();
    }
     
    
     
    |
    Mark as:
  • Currently Being Moderated
    Dec 19, 2011 3:53 PM   in reply to folkmane

    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  )

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 8, 2012 2:47 PM   in reply to Muppet Mark

    Hello everyone,

     

    I have been reviewing various replace scripts for symbols, the above two by JET and Wundes seem to be the most commonly referenced.

     

    Here is my question, I was hoping to add the ability to preserve rotation. So if the items being replaced had rotations already applied then the items replacing them would inherit that same rotation, hope that makes since.

     

    I was hoping I could store the rotation value to a variable like in JET's simple script for width, height etc., but it seems its not that easy. I began to think maybe it's just not possible since no one has included rotation preservation, so I contacted Wundes and he said it is possible and to look into using matrix transforms. Ugh, I looked at things in the JS Scripting Reference as well as Senocular's tutorial for Transform Matrix. However I cant seem to get my head around it enough to even know where to begin and probably I am not at the point realistically to add it to either of these scripts.

     

    JET's script is less involved, but Wundes script certainly offers some nice features, would someone be willing to walk me through or show me how to add rotation preservation to either of those two scripts. I would be really grateful and it would be a great learning experience for me with all this Matrix Transform stuff to see how it would be accomplished.

     

    I appreciate any help, feedback, scripts... thanks everyone.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 8, 2012 11:49 PM   in reply to W_J_T

    when an object is rotated, the application assigns a tag to it, you can tap into that tag's value an use it to rotate your symbol

     

    var idoc = app.activeDocument;
    var sel = idoc.selection[0];
    var rotationTag = sel.tags[0];
     
     
    alert(rotationTag.name + " : " + rotationTag.value + " Radians");
    
     
    |
    Mark as:
  • Currently Being Moderated
    Jun 9, 2012 1:05 AM   in reply to CarlosCanto

    Hi CarlosCanto, thanks so much for providing some feedback and input, its greatly appreciated.

     

    Thats an interesting tidbit concerning tags, I looked in the reference for tags and they seem is interesting, So is tag[0] an assignment or is it already assigned when rotated? I am pretty new to all this Illustrator scripting so I apologize. I tried adding the following two lines respectively with varying results as described below.

     

    var currRotation = currObj.tags[0];
    currInstance.rotate(currRotation.value * 180 / Math.PI);
    

     

    My math assigned in the rotate may not be correct :-(, but with this quick test it does in fact produce rotation (interesting this tag thing). I suspect there is more to it than this however? When an item is not rotated I was getting "Error: No such element" and when items are rotated they get replaced with what seems to be the "relative" rotation, however not perhaps entirely accurate. I also noticed depending on the rotation degree the scale or width/height seems altered as well. Also it seems like I need to clear the tag? Otherwise when running the script again it seems to add to the rotation.

     

    I hope I am making since, I doubt it, :-) as it is the middle of the night for me here and I have been staring at this issue, researching and fumbling around all evening to no avail, ugh!

     

    I appreciate any further feedback, advice, code and wisdom from yourself or others. Thanks again for your assistance CarlosCanto I really appreciate it. I think I am gonna get some sleep before my head hurts worse. Thanks again.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 9, 2012 1:40 AM   in reply to W_J_T

    you're welcome, yeah it's the middle of the night here too, pacific time.

     

    correct, if an object is not rotated, there's no tag, so you could do

     

    currObject.tags.length > 0 // then proceed, otherwise obj is not rotated

     

    your Math is correct, and the rotation you get is "absolute", regardless of how many times you have rotated the object. No need to clear the tag.

     

    regarding the sizing, you have to unrotate your object first, then read its width/height to size your symbol correctly,

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 9, 2012 2:46 AM   in reply to CarlosCanto

    What you doing in the middle of the pacific at night? And using AI to navigate? Get a GPS…

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 9, 2012 10:03 PM   in reply to CarlosCanto

    Hi CarlosCanto ( & Muppet Mark ;-),

     

    First of all I apologize, as I only started this Illustrator scripting a few weeks ago so sorry for my ignorance to things thus far. Its actually been going pretty well, but many things seem to elude me while others seem to be beyond me at this point.

     

    Thanks so much for the additional info CarlosCanto, tags.length worked to get around that issue. I also was able to zero out the rotation (which took some research and further headache) before gathering the width/height (* however see below). It now seems to scale accurately, but given the ratios of the original and new items it seems to locate top left and fit from there proportionally (* see below) perhaps due to the scale ratio part of the code?. So thanks so much for the heads up on both the tags.length and zeroing out rotation before hand, both helped. So I am inching along to further confusion and headaches. ;-) Is there a resource where can I find more detailed information about these "tag" assignments/values, I find little nuggets on the forum and some info in the Scripting Reference but was hoping to see maybe more detailed information if it exists.

     

    * Does the rotation tag get assigned to anything that has been rotated via the IDE as well also already rotated via obj.rotate(num) through code? To me it seems that items rotated with rotate() previously via javascript don't contain this tag, nor do Effect - Transform items, I cant target it to zero the rotation or rotate them to the previous rotation value? I cant seem to replace and retain rotation for something that has been rotated through code with rotate() already or via the Effect menu. But maybe I am wrong an just don't know how to target those, I am fumbling so much with this code trying to get it to work at all and trying to get all scenarios to work, I fix one break another, almost to the point of throwing in the towel and giving in to confusion. :-( I have tried so many things that I am even confused writing this as to what works, what doesn't, why, why not, at this point along with how to explain it. ;=) Forgive me. Ugh, I am at a loss, this whole rotation property seems rather challenging compared to the others given this request for outcome.

     

    My basic tests are as follows, I have been testing everything (even through possibly redundant), as I need this to work with ALL scenarios if possible. ;-)

     

    So far it works with these:

    - items rotated manually with the mouse

    - rotate tool

    - the transform window

    - right click transform

    - Ojbect - Transform - Rotate

     

    So far these do NOT work in retaining the present rotation:

    - Effect - Distort & Transform - Transform - Rotate  ( Also: scales fine but offsets its position, towards TL? )

    - Items rotated via Javascript using obj.rotate(num) ( Also: scales larger when replaced? )

    - When I run the script again, specifying a different symbol the rotation is lost

    - When I use symbol replace after applying the script the new replaced symbol does not retain the scale

     

    I hope I have stated those correctly, I have done so many tests with so many factors, approaches and code variations that I am thoroughly confused. So that seems to be the status update thus far, this whole rotation property seems rather challenging compared to the others, I guess since so many other factors are involved when that property is involved. I wish rotation was just rotation and could just be read and manipulated more easily. I was curious, even though it is beyound me, does using matrix transforms make this all easier and more straight forward vs tags or are both rather convoluted?

     

    So am I spinning my wheels thinking this approach can be achieved across all those scenarios? Any thoughts, feedback, code, or entire solutions :-) are welcome at this point. Thanks so much to CarlosCanto and everyone else, I greatly appreciate it.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 11, 2012 11:11 AM   in reply to W_J_T

    W_J_T wrote:

     

    * Does the rotation tag get assigned to anything that has been rotated via the IDE as well also already rotated via obj.rotate(num) through code? To me it seems that items rotated with rotate() previously via javascript don't contain this tag, nor do Effect - Transform items, I cant target it to zero the rotation or rotate them to the previous rotation value?

     

    Does anyone have any feeback on this part, that would really help me knowing that. If it exists for those items and if not what is the alternative then for them? Thanks everyone.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 11, 2012 12:53 PM   in reply to W_J_T

    WJT, I've read your posts… What kind of art are you replacing with symbols? Do you just want to swap one symbol for another or do you want to replace regular art objects with instances of symbols? Sorry but it may be a case of a picture saying a 1000 words… Im just not making the mental picture… I have no issue swapping one symbol for another regardless of later transforms…

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 11, 2012 9:10 PM   in reply to Muppet Mark

    Hi Muppet Mark,

     

    Speaking of mental picture, mine is quite cloudy on the topic at this point. Thanks for your reply, I really appreciate it.

     

    I am actually trying to target/replace both regular art items as well as items where symbols have already been applied already, and was hoping to do so over and over as needed or desired. As for the rotations and transformations I listed in my previous post as "working & not working", those things listed are things in which I am doing before hand then trying to retain those rotations, etc., and replace with a new symbol. As noted it works for some and not for others. Thats why I was wondering if perhaps the "tag" assignment for rotation is not applied when using javascript to rotate via obj.rotate(num) through code, the same goes for Effect - Distort & Transform - Transform - Rotate, I cant seem to taget items where these two things have already been done to an item, I cant seem to target the "tag" to zero the rotation before applying the width, height, location, rotation back to the new item which is replacing the old in those two instances. What I want is the ability to replace a regular piece of art or symbol regardless of its previous transformations, scale, rotation, have the code read these values and apply it to the new items.

     

    Clear as mud now right? ;-)

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 13, 2012 8:56 PM   in reply to W_J_T

    Is there anything I can do to help you guys be able to help me, since I am new to Illustrator scripting I would welcome any guidance/direction that can be offered. I tried to be as descriptive as possible in my above posts, do the issues/concerns/questions still remain confusing? Thanks everyone, I sincerely appreciate it.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 1, 2012 9:31 AM   in reply to W_J_T

    I am still seeking help on successfully adding rotation. The following is one of my attempted iterations:

     

    for (i = 0; i < selected.length; i++) {
        var currObj = selected[i];
        //
        if (currObj.tags.length > 0) {
            currObj.isRotated = true;
            var currRotation = currObj.tags[0];
            currObj.rotate((currRotation.value / (2 * Math.PI) * 360) * -1);
        }
        //
        var currLeft = currObj.left;
        var currTop = currObj.top;
        var currWidth = currObj.width;
        var currHeight = currObj.height;
        var currInstance = doc.symbolItems.add(doc.symbols[symbolNum - 1]);
        currInstance.width *= currWidth / currInstance.height;
        currInstance.height = currHeight;
        currInstance.left = currLeft;
        currInstance.top = currTop;
        //
        if (currObj.isRotated == true) {
            currInstance.rotate(currRotation.value * 180 / Math.PI);
        }
        //
        currInstance.selected = true;
        currObj.remove();
    }
    

     

    It yeilds the following as described in my previous posts above:

     

    rotation_results.png

     

    The reason for the "if" condition in the script is due to my previous asked question (post 10 above) as follows:

     

    W_J_T wrote:

     

    * Does the rotation tag get assigned to anything that has been rotated via the IDE as well also already rotated via obj.rotate(num) through code? To me it seems that items rotated with rotate() previously via javascript don't contain this tag, nor do Effect - Transform items, I cant target it to zero the rotation or rotate them to the previous rotation value?

     

    Without the if condition it throws an error "Error: No Such Element", thats why I added it assuming the tag is not applied as mentioned in the quote.

     

    I am really struggling to understand this approach using tags and find little information, documentation on tags in general or the BBAccumRotation which I assume is what the tag is referring to.

     

    I would really appreciate some guidance and support from more seasoned Illustrator scripters on this matter, I appreciate everyones time and welcome the feedback, advice, solutions. I am not sure what more I can provide in way of descriptions from what I have already outlined throughout this thread, I hope its clear enough for someone to assist me.

     

    Thanks everyone for your time and assistance.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 1, 2012 8:57 AM   in reply to Muppet Mark

    I am still hoping to figure this out from what I last posted. I could really use the help of more advanced and experienced Illustrator coders. Is there any further info I can provide to receive feedback and assitance? Thanks Muppet Mark and CarlosCanto thus far for what you have provided. Thanks again everyone.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 28, 2012 6:17 AM   in reply to Muppet Mark

    Muppet Mark wrote:

     

    Sorry but it may be a case of a picture saying a 1000 words… Im just not making the mental picture… I have no issue swapping one symbol for another regardless of later transforms…

     

    @ Muppet Mark

    @ CarlosCanto

     

    Can I provide any further information to receive assistance, or am I doing something wrong that I am no longer receiving help? I would greatly appreciate some feedback of some sorts. Thanks everyone for your time and considerations.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 28, 2012 12:05 PM   in reply to W_J_T

    I don't think this is the case of us not responding to you… but you must consider… A. it's not possible in AI script or B. we don't have the answer… ( I would have posted had I any solution )… AI is not like ID where matrix are live… In ID I can test/change rotation & skew, clear transformations etc. In AI I would suspect some of this is absolute when applied and I don't know how to help… It would appear that rotation & shear get tagged but I can't find any others… If your original item is square/rectangular why not math the angle & scale off something?

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 28, 2012 12:36 PM   in reply to Muppet Mark

    Hi Muppet Mark, thanks so much for the reply, good to know I was not black listed. ;-)

     

    My originals are not necessarily square (the image was just to explain further). Since items have a bounding box when selected (per say) are all items considered square when selected? If so what do you mean by your suggestion, I guess I am not following? I have tried messing with matrixes as well, I can zero something out but cant formulate otherwise and have had better success with the tags that were suggested here, but then ran into the roadblocks and limitations mentioned above.

     

    Thanks so much again for your reply, any feedback is welcome.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 28, 2012 12:50 PM   in reply to W_J_T

    Nobody is black listed… Only those that post a 1000 questions and don't mark 1 as either helpful or answered… Nobody has answered your request IMO…

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 28, 2012 10:46 PM   in reply to Muppet Mark

    hahahaha...that's right Mark, there's a couple of those that show up from time to time...

     

    wjt, I don't have an answer either, I tried but it seems like the bounding box does not get rotated...so, I ran into trouble, and still can't figure out a solution...but I'm curious, is it that critical you cover all possible rotation scenarios?

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 29, 2012 6:27 AM   in reply to CarlosCanto

    CarlosCanto wrote:

     

    wjt, I don't have an answer either, I tried but it seems like the bounding box does not get rotated...so, I ran into trouble, and still can't figure out a solution...but I'm curious, is it that critical you cover all possible rotation scenarios?

     

    Hi CarlosCanto, my whole idea behind coding this was initially for things previously rotated by code via obj.rotate(num) as well as Effect - Distort & Transform - Transform - Rotate. I am trying to automate some current processes and workflows, and even though the progress so far work for those other scenarios those are not actually the scenarios I was targeting or shooting for to begin with but in my testing process those were the only ones that worked as I tried to achieve the ones I actually had hoped for.

     

    I really appreciate the nuggets you and Muppet Mark have provided to get me this far and any further guidance or feedback is wholeheartedly welcome, thanks guys you have both been very helpful.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points