9 Replies Latest reply on Jan 17, 2016 5:40 PM by Qwertyfly...

    IllustratorSaveOptions confusion (expecting a_1.ai, but getting a_1_a_1.ai)

    joro126

      I'm trying to write a script that will save out all artboards, except for the first artboard, to their own ai files.  When I do save out each artboard, it takes the name of the artboard and appends it again resulting in something like a_1_a_1.ai instead of a_1.ai

       

      To explain better:

      1. Created artboard and named it "a_1"

      2. Created another artboard and named it "a_2"

      3. Ran script to export all artboards to individual files.

           This is what is given to determine the name and location of the saved file: docPath + "/" + doc.artboards[i].name;

      4. Artboards are saved, but are saved to "a_1_a_1.ai" and "a_2_a_2.ai".

       

      What am I missing here?

       

      Thanks!

        • 1. Re: IllustratorSaveOptions confusion (expecting a_1.ai, but getting a_1_a_1.ai)
          pixxxel schubser Level 5

          Hi joro126,

          without to see your save function (it's like a shot into the sky)

           

          But I think you save with artboard save option (saveOpts.saveMultipleArtboards = true). And that's why you not need the additional doc.artboards[i].name

          Try to save only the docpath + "/" docname. The name of artboard will be added automatically.

           

          Have fun

           

           

          <edited by pixxxel schubser>

          Perhaps some interesting stuff Rename artboards using their numbers

          (read the last posts in this thread too)

          • 2. Re: IllustratorSaveOptions confusion (expecting a_1.ai, but getting a_1_a_1.ai)
            joro126 Level 1
            var docRef = app.activeDocument;
            
            for (i=1; i<docRef.artboards.length;i++) {
                var aiSaveOptions = new IllustratorSaveOptions(); 
                aiSaveOptions.saveMultipleArtboards = true;
                aiSaveOptions.artboardRange = String(i+1);
            
                var filePath = docRef.path + "/" + docRef.artboards[i].name;
                var aiFile = new File(filePath);
                
                docRef.saveAs(aiFile, aiSaveOptions);
            }
            

             

            Basically, I just want the filename to be saved as the artboard name.  If the artboard is named "a_1" then I am expecting the filename to be named "a_1.ai".  Instead it is being named "a_1_a_1.ai".  Running your suggestion does something along the lines of "docName_a_1.ai" where docName is the name of the doc.

            • 3. Re: IllustratorSaveOptions confusion (expecting a_1.ai, but getting a_1_a_1.ai)
              CarlosCanto Adobe Community Professional & MVP

              unfortunately, that's how Illustrator saves the files using artboards, there's only two options,

               

              1. if the artboards aren't explicitly named, you get docName-01, docName-02

              2. if the artboards are explicitly named, you get docName_artboardNames

               

              you could try renaming your files after saving removing the docName portion.

              • 4. Re: IllustratorSaveOptions confusion (expecting a_1.ai, but getting a_1_a_1.ai)
                Qwertyfly... Level 4

                your for loop should start at 0 not 1, unless you dont want the first AB.

                it's happening due to the save multiple artboards option, but in this case you need it, from what I can tell anyway.

                simple fix is just to rename the files.

                here is a few extra lines that should work for you.

                 

                var docRef = app.activeDocument;  
                  
                for (i=0; i<docRef.artboards.length;i++) {  
                    var aiSaveOptions = new IllustratorSaveOptions();   
                    aiSaveOptions.saveMultipleArtboards = true;  
                    aiSaveOptions.artboardRange = String(i+1);  
                  
                    var filePath = docRef.path + "/" + docRef.artboards[i].name;  
                    var aiFile = new File(filePath);  
                      
                    docRef.saveAs(aiFile, aiSaveOptions);
                
                
                    renameFile = File(aiFile + "_" + docRef.artboards[i].name + ".ai");
                    renameFile.rename(docRef.artboards[i].name + ".ai");
                } 
                
                • 5. Re: IllustratorSaveOptions confusion (expecting a_1.ai, but getting a_1_a_1.ai)
                  joro126 Level 1

                  Thanks, I'll try this out.  Also, that is correct that I am starting from 1 because I don't need the first artboard.

                  • 6. Re: IllustratorSaveOptions confusion (expecting a_1.ai, but getting a_1_a_1.ai)
                    Qwertyfly... Level 4

                    all good, I assumed you needed it only because you talk about a_1 in your posts.

                    hope it does what you need...

                    • 7. Re: IllustratorSaveOptions confusion (expecting a_1.ai, but getting a_1_a_1.ai)
                      joro126 Level 1

                      It's very close, I did have to change it to use substrings because the path to the doc name includes the .ai extension.

                       

                          var subStr = filePath.substring(0, filePath.length-3);
                          renameFile = File(subStr + "_" + docRef.artboards[i].name + ".ai"); 
                          renameFile.rename(docRef.artboards[i].name + ".ai"); 
                      
                      • 8. Re: IllustratorSaveOptions confusion (expecting a_1.ai, but getting a_1_a_1.ai)
                        pixxxel schubser Level 5

                        Hi Qwertyfly...,

                        I don't think, that this is, what joro126 really want.

                         

                        IMHO something like this:

                        var docRef = app.activeDocument;
                        
                        for (i=1; i<docRef.artboards.length;i++) {
                            var aiSaveOptions = new IllustratorSaveOptions();
                            aiSaveOptions.saveMultipleArtboards = true;
                            aiSaveOptions.artboardRange = String(i+1);
                            
                            var filePath = docRef.path + "/" + docRef.name;
                            var aiFile = new File(filePath);
                            docRef.saveAs(aiFile, aiSaveOptions);
                            var ai2File1 = new File(docRef.path + "/" + aiFile.name.toString().replace(".ai","_"+docRef.artboards[i].name+".ai"));
                            var ai2File2 = new File(docRef.path + "/" + aiFile.name.toString().replace(".ai","-"+(i+1).toString().replace(/^.$/, "0" + (i+1))+".ai"));
                            if (ai2File1.exists) {
                            ai2File1.rename(docRef.artboards[i].name + ".ai");
                            } else {
                            ai2File2.rename((i+1).toString().replace(/^.$/, "0" + (i+1))+".ai");
                            }
                        }
                        

                         

                        I know, this is a little bit „like a shot from behind through the chest in the eye“, but … is works (for both cases original artboard names and renamed artboards too)

                         

                        (renamed) artboard a_1 will get the file a_1.ai

                        (original) artboard 1 will get the file 01.ai

                         

                        Have fun

                         

                        • 9. Re: IllustratorSaveOptions confusion (expecting a_1.ai, but getting a_1_a_1.ai)
                          Qwertyfly... Level 4

                          try to add,

                          alert(aiFile);

                          this will show "fullpath"/a_1  with no .ai.

                          I used this as a base and it worked fine for me.

                           

                          and Pixx, I'm not sure what is different about your solution.

                          we both end up with the correct file name by using .rename after the file has been saved. but yours is much more processing. Regex is great but not cheap, and in this case not required.

                          I did not bother with the if statement to test if the AB name was original or not, as this messes with the filename in some cases

                           

                          happy to be called out as misplaced if I have missed something!