0 Replies Latest reply on Jul 6, 2016 12:46 PM by RESlyder

    Collect text from symbols without breaking symbol?

    RESlyder

      Hi all,

       

      I am working on a script that exports our jpgs and adds all the text on the stage as metadata (docText) for easier searching of our graphics. I am able to collect all the textframes on the stage, but any text that is within symbols is left out. I had found a relatively complicated solution of making copies of the symbol, deleting the original and then relinking to the duplicated symbol, which would make sense if I wanted to change something, but all I want to do is peek inside and grab any textframes. We often use the same symbol multiple times (hence the whole point of using them) and when there were more than a few symbols on the stage the script would stall out trying to deal with all of them. And it was trying to duplicate the same symbol over and over. If I was able to catch it before it crashed sometimes there would be symbols named "Copy of Copy of Copy of..." which makes me thing that it isn't working as it should.

       

      I would love if I could find a way to just look inside the symbol to see if there is a text frame and if so get the contents of that text frame. Any ideas?

       

      I can't remember where I found this solution originally, but this is what I have:

      function getSymbolText(layerInfo){  
           if (layerInfo.symbolItems.length > 0){
           for (si = 0; si < layerInfo.symbolItems.length; si++){
               breakSymbol(layerInfo.symbolItems[si].symbol);
               }
           }
       };
          // return true;  
      
      function breakSymbol(Ssource){
          try{
              var a=UnlinkSymbol(Ssource); // unlink  
              getText(a); // create outline for text  
              var Scopy=Ssource.parent.symbols.add(Ssource.parent.layers.getByName(a.name).groupItems[0]); //make copy of symbol  
              Scopy.name="Copy of "+Ssource.name; // name it  
              var storedName = Ssource.name;
              Ssource.parent.layers.getByName(a.name).remove(); // remove temp layer  
              replaceSymbol(Ssource,Scopy); // exchange them  
                
              Ssource.remove(); //remove original symbol 
              Scopy.name = storedName;
              }
          catch(e){}
      }  ;
      //******************************//   
      function UnlinkSymbol(symb){  
           var Ltemp=symb.parent.layers.add()  
           Ltemp.name="temp";
           var D=symb.duplicate();    
           Ltemp.symbolItems.add(D);  
           D.remove()  
           return Ltemp;  
           } ; 
      //******************************//   
      function getText (groupRef) {  
           var textItemsList =  new Array();  
           if (groupRef.groupItems.length > 0) {  
                for (var h = 0 ; h < groupRef.groupItems.length; h++) {  
                var theGroupItems = (getText (groupRef.groupItems[h]));  
                     for (var gr = theGroupItems.length -1; gr > -1; gr--) {
                         if (theGroupItems[gr].contents != undefined){
                         docText += theGroupItems[gr].contents+ "; ";
                         }
                     }  
                }  
           }  
        
           if (groupRef.textFrames.length > 0) {  
           for (var h = 0 ; h < groupRef.textFrames.length; h++) {
               docText += groupRef.textFrames[h].contents+ "; ";
               }  
           }  
        
           if (groupRef.legacyTextItems.length > 0) {  
           for (var h = 0 ; h < groupRef.legacyTextItems.length; h++) {  
               var theTextFrame = groupRef.legacyTextItems[h].convertToNative()  
               docText += theTextFrame.contents+ "; ";  
                }  
           }  
      return textItemsList  
      }; 
      //******************************//   
      function replaceSymbol(S,C){  
          for (r=S.parent.symbolItems.length-1;r>-1;r--){
              if (S.parent.symbolItems[r].symbol==S){
                  S.parent.symbolItems[r].symbol=C
              }
          }       
      };