9 Replies Latest reply on Dec 30, 2015 12:39 PM by shawnbeel

    Script to convert all text to paths and save out artboards

    shawnbeel

      I'm wondering if there's a way to convert all text to paths, even text within symbols, and then export each artboard to it's own file. This would be for creating flat files to upload to a printing service. Bonus would be to also remove unused symbols and hidden layers. Is this possible with scripting?

        • 1. Re: Script to convert all text to paths and save out artboards
          Vinicius Baptista Level 2

          Hi, I croped a part of my script and it convert texts to Outlines, see:

           

          #target illustrator
          #targetengine main
          
          
          
          
          if ( app.documents.length > 0 ) {
          
          
          var docRef = app.activeDocument;
          var textsDoc = docRef.textFrames.length;
          
          
          //Create progress window
          var dlgProgress = new Window ('palette', 'Loading...', undefined, {closeButton: false});
          dlgProgress.orientation = 'column';
          dlgProgress.alignChildren = 'fill';
          
          
          var txtWait = dlgProgress.add('statictext', undefined, '');
          txtWait.characters = 40;
          
          
          var progress = dlgProgress.add('progressbar');
          //--------------------------------------------------------------------------------
          
          
          //Function to converted all texts in docRef to outline
          var allTextOutline = function (){
          
          
          txtWait.text = 'Converting All texts.';
          
          
          dlgProgress.show();
          
          
          progress.maxvalue = textsDoc;
          
          
          for ( var i = textsDoc-1; i >= 0; i-- ) {
              if (docRef.textFrames[i].locked){
                  docRef.textFrames[i].createOutline().locked = true;
              }else if (docRef.textFrames[i].hidden){
                  docRef.textFrames[i].createOutline().hidden = true;
              }else{
                  docRef.textFrames[i].createOutline();
                  };
              progress.value ++;
              dlgProgress.update();
          };
          dlgProgress.close();
          };
          //--------------------------------------------------------------------------------
          
          
          if (textsDoc > 0){
              allTextOutline ();
              };
          
          
          
          
          alert('Finished.\nTexts converted to outline ' + textsDoc + '.' + '\nDeveloper by: Vinícius Dias\nvbaptistacg@gmail.com');
          }else{
              alert("Don't have opened files.");
          };
          

           

          Hope it helps, I will try write one script to export artboards.

           

          Best regards,

          -Vinicius

          • 2. Re: Script to convert all text to paths and save out artboards
            Vinicius Baptista Level 2

            On time, look below if it works to you:

             

            #target illustrator  
            #targetengine main  
              
            if ( app.documents.length > 0 ) {  
              
              
            var docRef = app.activeDocument;  
            var textsDoc = docRef.textFrames.length;  
            var dest = Folder.selectDialog ("Choose a folder to save the file(s)");
            var ABCount = docRef.artboards.length;
              
            //Create progress window  
            var dlgProgress = new Window ('palette', 'Loading...', undefined, {closeButton: false});  
            dlgProgress.orientation = 'column';  
            dlgProgress.alignChildren = 'fill';  
              
              
            var txtWait = dlgProgress.add('statictext', undefined, '');  
            txtWait.characters = 40;  
              
              
            var progress = dlgProgress.add('progressbar');  
            //--------------------------------------------------------------------------------  
              
              
            //Function to converted all texts in docRef to outline  
            var allTextOutline = function (){  
              
              
            txtWait.text = 'Converting All texts.';  
              
              
            dlgProgress.show();  
              
              
            progress.maxvalue = textsDoc;  
              
              
            for ( var i = textsDoc-1; i >= 0; i-- ) {  
                if (docRef.textFrames[i].locked){  
                    docRef.textFrames[i].createOutline().locked = true;  
                }else if (docRef.textFrames[i].hidden){  
                    docRef.textFrames[i].createOutline().hidden = true;  
                }else{  
                    docRef.textFrames[i].createOutline();  
                    };  
                progress.value ++;  
                dlgProgress.update();  
            };  
            dlgProgress.close();  
            };  
            //--------------------------------------------------------------------------------  
              
              
              
            function exportFileToAI (dest) {
            
            
            txtWait.text = 'Saving...';  
              
            dlgProgress.show();  
              
            progress.maxvalue = ABCount;
            progress.value = 0;
            
            
            for (i = 1; i <= ABCount; i++){
            
            
            var aiDoc = new File(dest + "/Artboard_" + i + "_" + app.activeDocument.name);
            var saveOpts = new IllustratorSaveOptions();
            saveOpts.compatibility = Compatibility.ILLUSTRATOR17;
            saveOpts.flattenOutput = OutputFlattening.PRESERVEAPPEARANCE;
            saveOpts.PDFCompatibility = true;
            saveOpts.embedICCProfile = true;
            saveOpts.compressed = true;
            saveOpts.artBoardClipping = true;
            saveOpts.saveMultipleArtboards = true;
            saveOpts.artboardRange = ABCount;
            app.activeDocument.saveAs(aiDoc, saveOpts);
            
            
            progress.value ++;  
            dlgProgress.update();  
            
            
            };
            dlgProgress.close();
            };
            
            
            if (dest){
                if (textsDoc > 0){
                allTextOutline ();  
                };
            }else{
            textsDoc = 0;
            };
            
            
            if (dest){
                exportFileToAI (dest);
                }else{
                i = 0;
            };
            
            
            alert('Finished.\nTexts converted to outline ' + textsDoc + '.' + '\nArtboards Exported ' + i + '.' + '\nDeveloper by: Vinícius Dias.\nvbaptistacg@gmail.com');  
            }else{  
                alert("Don't have opened files.");  
            };  
            

             

            Cheers!!!

            -Vinicius.

            • 3. Re: Script to convert all text to paths and save out artboards
              Vinicius Baptista Level 2

              I owe you just the removal of symbols, when I can I'll write it.

               

              //loop to remove invisible layers
              
              
              for (f = app.activeDocument.layers.length-1; f >= 0; f--){
                  if (app.activeDocument.layers[f].visible == false){
                      app.activeDocument.layers[f].visible = true;
                      app.activeDocument.layers[f].remove();
                  };
              };
              

               

              See you,

              -Vinicius

              • 4. Re: Script to convert all text to paths and save out artboards
                shawnbeel Level 1

                Hey Vinicius - Thanks for this, I appreciate it! Unfortunately it didn't work for me... Maybe because I'm still using AI CS6? Sorry, I should have mentioned that right off. Here's the error I get when running the 2nd script above:

                Error 8705: Target layer cannot be modified

                Line 47

                -> docRef.textFrames[i].createOutline();

                • 5. Re: Script to convert all text to paths and save out artboards
                  shawnbeel Level 1

                  This didn't work either (please see my other reply)... Not sure if it's because I'm using CS6... Thanks!

                  • 6. Re: Script to convert all text to paths and save out artboards
                    Vinicius Baptista Level 2

                    Hi, Don't worry, maybe the error really occurred because the illustrator version is older, I created in CC version, however now I have tested in windows AI CS6 and it worked normally, and I found one mistake on my code hahaha but I correct it, please try again with the code below:

                     

                    #target illustrator    
                    #targetengine main    
                        
                    if ( app.documents.length > 0 ) {    
                        
                        
                    var docRef = app.activeDocument;    
                    var textsDoc = docRef.textFrames.length;    
                    var dest = Folder.selectDialog ("Choose a folder to save the file(s)");  
                    var ABCount = docRef.artboards.length;  
                        
                    //Create progress window    
                    var dlgProgress = new Window ('palette', 'Loading...', undefined, {closeButton: false});    
                    dlgProgress.orientation = 'column';    
                    dlgProgress.alignChildren = 'fill';    
                        
                        
                    var txtWait = dlgProgress.add('statictext', undefined, '');    
                    txtWait.characters = 40;    
                        
                        
                    var progress = dlgProgress.add('progressbar');    
                    //--------------------------------------------------------------------------------    
                        
                        
                    //Function to converted all texts in docRef to outline    
                    var allTextOutline = function (){    
                        
                        
                    txtWait.text = 'Converting All texts.';    
                        
                        
                    dlgProgress.show();    
                        
                        
                    progress.maxvalue = textsDoc;    
                        
                        
                    for ( var i = textsDoc-1; i >= 0; i-- ) {    
                        if (docRef.textFrames[i].locked){    
                            docRef.textFrames[i].createOutline().locked = true;    
                        }else if (docRef.textFrames[i].hidden){    
                            docRef.textFrames[i].createOutline().hidden = true;    
                        }else{    
                            docRef.textFrames[i].createOutline();    
                            };    
                        progress.value ++;    
                        dlgProgress.update();    
                    };    
                    dlgProgress.close();    
                    };    
                    //--------------------------------------------------------------------------------    
                        
                        
                        
                    function exportFileToAI (dest) {  
                      
                      
                    txtWait.text = 'Saving...';    
                        
                    dlgProgress.show();    
                        
                    progress.maxvalue = ABCount;  
                    progress.value = 0;  
                      
                      
                    for (i = 1; i <= ABCount; i++){  
                      
                      
                    var aiDoc = new File(dest + "/" + app.activeDocument.name + "Artboard_" + i);  
                    var saveOpts = new IllustratorSaveOptions();  
                    saveOpts.compatibility = Compatibility.ILLUSTRATOR16;  
                    saveOpts.flattenOutput = OutputFlattening.PRESERVEAPPEARANCE;  
                    saveOpts.PDFCompatibility = true;  
                    saveOpts.embedICCProfile = true;  
                    saveOpts.compressed = true;  
                    saveOpts.artBoardClipping = true;  
                    saveOpts.saveMultipleArtboards = true;  
                    saveOpts.artboardRange = i;  
                    app.activeDocument.saveAs(aiDoc, saveOpts);  
                      
                      
                    progress.value ++;    
                    dlgProgress.update();    
                      
                      
                    };  
                    dlgProgress.close();  
                    };  
                      
                      
                    if (dest){  
                        if (textsDoc > 0){  
                        allTextOutline ();    
                        };  
                    }else{  
                    textsDoc = 0;  
                    };  
                      
                      
                    if (dest){  
                        exportFileToAI (dest);  
                        }else{  
                        i = 0;  
                    };  
                    
                    
                    i--;
                    if (i < 0){i = 0};  
                    
                    
                    alert('Finished.\nTexts converted to outline ' + textsDoc + '.' + '\nArtboards Exported ' + i + '.' + '\nDeveloper by: Vinícius Dias.\nvbaptistacg@gmail.com');    
                    }else{    
                        alert("Don't have opened files.");    
                    };
                    

                     

                    If it is still wrong please perform this script in this test file it works in my tests:

                     

                    https://www.sendspace.com/file/2r4oi3

                     

                    Maybe your file have any particularity and I need see it:

                    So, I hope now works.

                     

                    See, -Vinícius.

                    • 7. Re: Script to convert all text to paths and save out artboards
                      shawnbeel Level 1

                      I tried your revised script on my working file but got the same error (this time for line 45).

                       

                      I was able to run the script on your test AI file successfully, though. But, when I have text inside a symbol instance, it doesn't convert that text to paths. Maybe that's not possible?

                      • 8. Re: Script to convert all text to paths and save out artboards
                        Vinicius Baptista Level 2

                        Hello, I created a loop to unlock all layers and memorize the locked layers before perform the task and after concluded, lock again these layers, the error that was returned in line 45 must be solved, please try it again, sorry for the confusion.

                         

                        #target illustrator      
                        #targetengine main      
                              
                        if ( app.documents.length > 0 ) {      
                              
                              
                        var docRef = app.activeDocument;      
                        var textsDoc = docRef.textFrames.length;      
                        var dest = Folder.selectDialog ("Choose a folder to save the file(s)");    
                        var ABCount = docRef.artboards.length;    
                        var tLayers = docRef.layers.length;
                        var lockedLayers = [];
                        
                        
                        
                        
                        //Unlock all layers and memorize lockeds layers
                        for (i = 0; i < tLayers; i++){
                            if (docRef.layers[i].locked){
                                lockedLayers.push(i);
                                docRef.layers[i].locked = false;
                            };
                        };
                        //------------------------------------------
                        
                        
                        
                        
                        //Create progress window      
                        var dlgProgress = new Window ('palette', 'Loading...', undefined, {closeButton: false});      
                        dlgProgress.orientation = 'column';      
                        dlgProgress.alignChildren = 'fill';      
                              
                              
                        var txtWait = dlgProgress.add('statictext', undefined, '');      
                        txtWait.characters = 40;      
                              
                              
                        var progress = dlgProgress.add('progressbar');      
                        //--------------------------------------------------------------------------------      
                              
                              
                        //Function to converted all texts in docRef to outline      
                        var allTextOutline = function (){      
                              
                              
                        txtWait.text = 'Converting All texts.';      
                              
                              
                        dlgProgress.show();      
                              
                              
                        progress.maxvalue = textsDoc;      
                              
                              
                        for ( var i = textsDoc-1; i >= 0; i-- ) {      
                            if (docRef.textFrames[i].locked){      
                                docRef.textFrames[i].createOutline().locked = true;      
                            }else if (docRef.textFrames[i].hidden){      
                                docRef.textFrames[i].createOutline().hidden = true;      
                            }else{      
                                docRef.textFrames[i].createOutline();      
                                };      
                            progress.value ++;      
                            dlgProgress.update();      
                        };      
                        dlgProgress.close();      
                        };      
                        //--------------------------------------------------------------------------------      
                              
                              
                              
                        function exportFileToAI (dest) {    
                            
                            
                        txtWait.text = 'Saving...';      
                              
                        dlgProgress.show();      
                              
                        progress.maxvalue = ABCount;    
                        progress.value = 0;    
                            
                            
                        for (i = 1; i <= ABCount; i++){    
                            
                            
                        var aiDoc = new File(dest + "/" + app.activeDocument.name + "Artboard_" + i);    
                        var saveOpts = new IllustratorSaveOptions();    
                        saveOpts.compatibility = Compatibility.ILLUSTRATOR16;    
                        saveOpts.flattenOutput = OutputFlattening.PRESERVEAPPEARANCE;    
                        saveOpts.PDFCompatibility = true;    
                        saveOpts.embedICCProfile = true;    
                        saveOpts.compressed = true;    
                        saveOpts.artBoardClipping = true;    
                        saveOpts.saveMultipleArtboards = true;    
                        saveOpts.artboardRange = i;    
                        app.activeDocument.saveAs(aiDoc, saveOpts);    
                            
                            
                        progress.value ++;      
                        dlgProgress.update();      
                            
                            
                        };    
                        dlgProgress.close();    
                        };    
                            
                            
                        if (dest){    
                            if (textsDoc > 0){    
                            allTextOutline ();      
                            };    
                        }else{    
                        textsDoc = 0;    
                        };    
                            
                            
                        if (dest){    
                            exportFileToAI (dest);    
                            }else{    
                            i = 0;    
                        };    
                          
                          
                        i--;  
                        if (i < 0){i = 0};    
                          
                          
                        alert('Finished.\nTexts converted to outline ' + textsDoc + '.' + '\nArtboards Exported ' + i + '.' + '\nDeveloper by: Vinícius Dias.\nvbaptistacg@gmail.com'); 
                        
                        
                        //Lock the layers that was locked
                        for (i = 0; i < lockedLayers.length;i++){
                            docRef.layers[lockedLayers[i]].locked = true;
                        };
                        //---------------------------------
                        
                        
                        }else{      
                            alert("Don't have opened files.");      
                        };
                        

                         

                        -Vinícius

                        • 9. Re: Script to convert all text to paths and save out artboards
                          shawnbeel Level 1

                          Vinicius - This seems to be working for the most part, thanks.

                           

                          Do you know if it is possible for the script to convert text to outlines that is within a symbol?

                           

                          You're very generous to help me with this, I really appreciate it!