Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Why does JavaScript have the file name correct but then save Differently?

Engaged ,
Dec 01, 2021 Dec 01, 2021

Hello, I have Script that recognizes the naming scheme correctly but then saves incorrectly.

Naming Scheme is 9999999-1.ai, 9999999-2.ai

but the file saves as 9999999-1-01.ai, 9999999-2-02.ai

 

Any ideas how I can fix this?

 

 

var doc = app.activeDocument;
var boards = doc.artboards;
var strEnter = doc.name; //alert(strEnter);
var soNum = strEnter.slice(0,7);
var myNum = 1;
var arrayCount;
var arrayLength;
var arr;
var sc = "/";   
var folderPrefix = sc + sc + "idp-fs-02" + sc + "data" + sc + "Graphics" + sc + "LaserCube" + sc;
var searchString1 = /\d{7}/;
var searchString2 = /(\d)(\d)(\d)/;
var first = "000000";
var last = "999999";

if (strEnter != null && searchString1.test(strEnter) === true) {
    var strEnter = strEnter.replace(/^0+/, '');  
    var str = null;
    var arr = strEnter.match (searchString2);
    var folder1 = shorten (arr[1], first) +"-"+ shorten (arr[1], last) + sc;
    var folder2 = shorten (arr[1]+arr[2], first) +"-"+ shorten (arr[1]+arr[2], last) + sc;
    var folder3 = shorten (arr[1]+arr[2]+arr[3], first) +"-"+ shorten (arr[1]+arr[2]+arr[3], last) + sc;
    var folderString = (folderPrefix + folder3); 

        function shorten (strt1, num) {
            str = strt1 + num;
            return str = str.slice(0, 7);
            }
            
            activeFolder = new Folder (folderString);
if (activeFolder.exists === false) {
    activeFolder.create();
    }

// loop through all artboards, make each one active and render before moving onto the next
for(var i = 0; i < boards.length; i++) {
    doc.artboards.setActiveArtboardIndex(i);
    var saveOptions = new IllustratorSaveOptions()
    saveOptions.saveMultipleArtboards = true;
    saveOptions.artboardRange = (i+1).toString();
    var aiDoc = new File(folderString + soNum + ("-" + (i+1).toString()) + ".ai"); alert(aiDoc);
    doc.saveAs(aiDoc, saveOptions);
    }   
}

 

Capture.PNGexpand image

 

TOPICS
Scripting
302
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 01, 2021 Dec 01, 2021

I believe it's the artboardRange setting that is adding that extra suffix. Instead of saving a specified artboard range, you can try something like this pseudo-code.

 

//store the size/position of the existing artboards so we can replace them at the end

artboardInfo =  [2d array holding the artboardRect of each artboard in the document]

 

while artboards.length > 1

    remove last artboard

 

for each artboard in artboardInfo

    document.artboards[0].arboardRect = artboardInfo[i]

    save file w

...
Translate
Adobe
Community Expert ,
Dec 01, 2021 Dec 01, 2021

Hi,

01, 02 at the end of the actual file names, represrnt the artboards, because you are saving each arboard as an ai file.

Best regards
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 01, 2021 Dec 01, 2021
LATEST

I believe it's the artboardRange setting that is adding that extra suffix. Instead of saving a specified artboard range, you can try something like this pseudo-code.

 

//store the size/position of the existing artboards so we can replace them at the end

artboardInfo =  [2d array holding the artboardRect of each artboard in the document]

 

while artboards.length > 1

    remove last artboard

 

for each artboard in artboardInfo

    document.artboards[0].arboardRect = artboardInfo[i]

    save file without specifying artboard range

 

//edit because i forgot to include this final part of the logic to reset the artboards

for each artboardRect in artboardInfo

    draw an artboard on the document with this artboardRect

 

remove artboards[0]

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines