Skip navigation
Currently Being Moderated

[JS] Break Link to Symbol || Outline text contained within symbol

Dec 31, 2008 9:58 AM

There are a set of symbols in my documents, these all contain editable text.
Prior to going to production I need to break the link to all the symbols so that I can outline the text. SymbolItem doesn't have a method that i have uncovered - suggestions?

Thanks
 
Replies
  • Currently Being Moderated
    Apr 3, 2009 3:32 AM   in reply to (JohnDArmstrong)
    I've got a very similar problem in that when I add a symbol instance to the document, I want to be able to change the fill/stroke colors of the individual parts of that symbol (be they simple paths or symbols themselves). I know how to change the fill/stroke of a simple symbol instance (ie: a single color 'silhouette') using Graphic Styles however, when you try this approach with a 'compound' symbol the settings are applied to the symbol as a whole - there is no way to target the nested items separately. The 'Break Link to Symbol' command is exactly what I need but it does not seem to be available via scripting - very frustrating!!!

    Anyone with any ideas how John & I can around this?

    Cheers
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 9, 2009 8:13 AM   in reply to Andy_McDonald

    Just looking for an update on whether the ability to break the link between a SymbolItem on the artboard and the corresponding Symbol in the library will be exposed through the API for CS5 as this would make working with symbols via scripting a whole lot easier - it seems crazy that I have to resort to a hack using GraphicStyles just to change the stroke and fill colors of a SymbolItem.

     

    Alternatively (or additionally), it would be really handy if the nested structure of a symbolItem could be accessed / manipulated through its properties (ie: symbolItems, pathItems, groupItems, etc. where properties of the symbolItem). For instance, by simply accessing its list of pathItems, I could change the stroke / fill colors in the same way as you would with any other pathItem. The real benefit is being able to access individual sub-components of the symbolItem.

     

     

     

    Many thanks,

     

     

     

     

    Andy McDonald

    Centre for Advanced Textiles

    Glasgow School of Art

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 9, 2009 8:44 AM   in reply to Andy_McDonald

    maybe i`m talking non-sense(as i usually do), but why dun you do something like this:

     

    var myDamnAnnoyingSymbol = app.activeDocument.selection[0];

    var myMainDocument = app.activeDocument;

    var myTempDocument = app.documents.add();

     

    //not sure what will happen here ... but let's be sure

    app.activeDocument = myMainDocument;

     

    myDamnAnnoyingSymbol.duplicate(myTempDocument, ElementPlacement.PLACEATBEGINNING);

    myDamnAnnoyingSymbol.remove();

     

    var _tSel = myTempDocument.pageItems[0];

     

    //let's kill the linkage thus breaking the symbol

    _tSel.symbol.remove();

     

    //copy it back because now we should have only a group

    _tSel =  myTempDocument.pageItems[0].duplicate(myMainDocument, ElementPlacement.PLACEATBEGINNING);

     

     

    The above should copy the symbol no a new document, break the symbol there, and bring it back while keeping intact your current symbol library(so it should ):

     

    if you dun care about the symbols in library:

     

    //select the symbol object in a loop of something

    for(j = app.activeDocument.pageItems.length-1; j >= 0; j--){

         if(app.activeDocument.pageItems[j].typename == "SymbolItem") app.activeDocument.pageItems[j].symbol.remove();

    }

     

     

    hope this somehow helps your goal.

    cheers;

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 9, 2009 3:48 PM   in reply to sonicDream

    Hi sonicDream!

     

     

    Great work! I had not thought about using a secondary document in this 

    way. The advantage is that you can re-use the same document each time 

    you need to break a symbol link (ie: you only need 2 documents open). 

    That being said, if your symbol contains other symbols then these also 

    need to be 'unpacked' which will probably require additional documents 

    (ie: number of extra documents = number of nested levels).

     

    Whilst this certainly solves my immediate problem, it still seems 

    unnecessarily complicated. I'd still like to see an easier way to 

    break symbol links make it into the DOM - can someone from Adobe 

    please update us on the situation?

     

     

     

    Thanks again,

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 9, 2009 10:42 PM   in reply to Andy_McDonald

    You need only one document to make all the "background work" ... it's not complicated since you can do the following: get the symbol, move it to the new document and access every pathItem with document.pathItems( probably the same with textframes) because document.pathItems will return every and each pathItem even if those are in a clipping mask, group or whatever else. It would be nicer a bit accessing those objects in a more decent manner, but imho this will do jut fine for now. Beside that you can build a symbol helper class to make the whole process more than accesible to whatever you want to accomplish.

     

    hope it helps.

    cheers;

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 11, 2009 4:53 AM   in reply to sonicDream

    Unfortunately it's not quite that simple because pathItems contained within a symbolItem do not show up in the document.pathItems collection therefore you need to cycle through the nested structure of the symbol to unpack any symbols that are inside.

     

    I'm still trying to find an elegant way to do this due to the fact that when you remove a symbolItems corresponding symbol then it is automatically turned into a group and placed at the top of the topmost layer - this makes looping difficult as items are being removed from the collection whilst the loop is being executed.

     

     

     

     

     

     

    Andy McDonald

    Centre for Advanced Textiles

    Glasgow School of Art

     

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 13, 2009 2:59 PM   in reply to Andy_McDonald

    As i already said is not that difficult ... this script turns your symbol into a nice bunch of pathitems:

     

    #target illustrator
    var doc = app.activeDocument;
    var doc2 = app.documents.add();

     

    var SymbolHelper = {
            getSymbols: function() {
                var syms = new Array();
                for(i=0; i < doc.pageItems.length; i++) {
                  
                    if(doc.pageItems[i].typename=="SymbolItem") {
                        syms.push(doc.pageItems[i]);
                    }
                }
              
                return syms;
            },
            moveAndBreakSymbol: function(sym) {
                try { sym.duplicate(doc2, ElementPlacement.PLACEATBEGINNING); } catch(ex) {};
            },
            clearSymbols: function() {
                try { doc2.symbols.removeAll(); } catch(ex){}
            },
            makeMePlainAndSweet: function(group) {
                var sorted =group.pageItems;
                for(e = sorted.length - 1; e>= 0; e--) {
                    sorted[e].move(group, ElementPlacement.PLACEBEFORE);
                }
            },
            makeMePlainAndSweetBatch: function() {
                var doAfter = new Array();
              
                for(x = doc2.groupItems.length - 1; x >= 0;x--) {
                    //alert(doc2.groupItems[x].groupItems.length);
                    if(doc2.groupItems[x].groupItems.length > 0) doAfter.push(doc2.groupItems[x]);
                    else this.makeMePlainAndSweet(doc2.groupItems[x]);
                }
               if(doAfter.length > 0) {
                    for(i = doAfter.length - 1; i >= 0; i--) {
                        this.makeMePlainAndSweet(doAfter[i]);
                    }
                }
            },

     

    }

     

    var syms = SymbolHelper.getSymbols();
    for(i = syms.length - 1; i >= 0; i--) {
        SymbolHelper.moveAndBreakSymbol(syms[i]);
    }
    SymbolHelper.clearSymbols();
    SymbolHelper.makeMePlainAndSweetBatch();

     

    The only downside of the javascript aproach(that's either because i`m too stupid/tired @ this hour) is that the elements inside the groups are taken out in their index order and not their zOrder(using zOrderPosition on elements inside the group gives me an internal error) because of some random reason.

    The rest of the script is fairly easy and that's bringing back the elements.

     

    hope it somehow helps;

    cheers;

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 29, 2010 9:19 AM   in reply to sonicDream

    I tried altering this script to my needs, but i can't seem to get it to work. here is what i need.

     

    I just want to be able to pull a symbol out into my current doc and break the link so it's back to live text.

     

    sorry for bumping an old post, thought it would be better than making a new one.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 29, 2010 10:12 AM   in reply to jimmytroilo

    hi Jimmy,

     

    jimmytroilo a écrit:

     

    I tried altering this script to my needs, but i can't seem to get it to work. here is what i need.

     

    I just want to be able to pull a symbol out into my current doc and break the link so it's back to live text.

     

    sorry for bumping an old post, thought it would be better than making a new one.

    may be you need to read this post

     

    My method is to duplicate symbol , (i haven't need to create a new doc just put it on a layer (here you can modify what you want -- for me it's to createoutline text -- ), check all instance of old symbol and replace by the new one.

     

    feel free to ask me any questions

     

    regards, art.chrome

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 29, 2010 10:25 AM   in reply to artchrome

    Thanks for the quick reply, good comments on that code helped me modify it, but i can't figure out the break link code to keep it as live text instead of outlines. I didn't try too long so I'll work on it later since my lunch break is over. again, thanks for the quick reply and help!

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 30, 2010 1:35 AM   in reply to jimmytroilo

    Hi Jimmy,

     

    So see below:

     

    #target illustrator
    var doc=activeDocument;
     
     var a=UnlinkSymbol(doc.symbols[0]); // unlink
     
    a.groupItems[0].pageItems[0].contents="changed!"
     
    //******************************// 
    function UnlinkSymbol(symb){
         var Ltemp=symb.parent.layers.add()
         Ltemp.name="temp";
         var D=symb.duplicate(); // this and...
         Ltemp.symbolItems.add(D);  // this and...
         D.remove() ;// this break the link, because this new symbol isn't instancied
         return Ltemp;
         }
    //******************************//
    

     

    To experiment this script,

    - make a new doc without symbol

    - create a simple symbol (for exemple i've used a rectangle under a text, and drag&drop in symbols board)

    - run the script

    Image 6.png

    I hope this will be helpfull to understand it

     

    Regards, art.chrome

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 30, 2010 7:55 AM   in reply to artchrome

    great, i modified it to work with my workflow, thank you so much.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)