unexpected placement of artboard when copying between files via script
I'm working on a script that splits a file with many artboards into several smaller files.
The problem is happening when the script tries to create a new board in a destination file. The error is consistent with similar errors I've had when something would cause an artboard to fall off the canvas.
When I run the script, it is sometimes able to set up a few boards before running into the error. I can see that the boards in the new file are not in the same position as the old file. The document height/width and the artboardRect are coming directly from the source document/artboard. It doesn't make sense how the placement could change. The script also runs into the error at different times depending on whether I've just opened the source file or if I'm running the script a second time. I don't believe the script makes any change to the source file.
//woven is an array of Board objects. each Board is initailized with an artboard object and an index that references that artboard's position in the document.artboards[] array.
if(woven.length > 0){
var wovenDoc = app.documents.add(DocumentColorSpace.RGB, currentDoc.width, currentDoc.height);
for (i=0; i<woven.length; i++) {
app.activeDocument = currentDoc;
//copy art
currentDoc.artboards.setActiveArtboardIndex(woven[i].index);
currentDoc.selectObjectsOnActiveArtboard();
app.copy();
app.selection=[];
//prepare info for new artboard
var boardRect = woven[i].artboard.artboardRect;
var boardName = woven[i].artboard.name;
//create new board and paste art
app.activeDocument = wovenDoc;
wovenDoc.artboards.add(boardRect);
wovenDoc.artboards[wovenDoc.artboards.length-1].name = boardName;
wovenDoc.artboards.setActiveArtboardIndex(wovenDoc.artboards.length-1);
app.executeMenuCommand("pasteInPlace");
}
//a blank artboard was created when the document was added. it can be removed now.
wovenDoc.artboards.remove(0);
