Copy link to clipboard
Copied
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);
}
}
1 Correct answer
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
...Explore related tutorials & articles
Copy link to clipboard
Copied
Hi,
01, 02 at the end of the actual file names, represrnt the artboards, because you are saving each arboard as an ai file.
Copy link to clipboard
Copied
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]

