var y = -50; //artboard top margin to place art
var x = 43; //artboard left margin to place art
var actIdx = docRef.artboards.getActiveArtboardIndex();
var actAB = docRef.artboards[actIdx];
for (i = 0; i < iCnt; i++) {
artType = xmlRoot.child(i).child(0).text();
docRef.artboards.setActiveArtboardIndex (1);
if(artType == gpRefName) { //tests xmlValue.name against groupItem.name; if match go ahead
dupArt = gpRef.duplicate(tgLay, ElementPlacement.INSIDE);
dupArt.top = actAB.artboardRect[1] + y;
dupArt.left = actAB.artboardRect[0] + x;
x+=(gpRef.width + 18);
//check for overflow of artboard X; start new row
if(dupArt.geometricBounds[0] >= actAB.artboardRect[2] ) { //if left edge of dupArt is overlapping right edge of artboard
y+= -dupArt.height + -94; //-94 adds some space between the rows
x = 43;
}
//check for overflow of artboard Y; create new artboard and start at top -50 & x 43 of new artboard
if(dupArt.geometricBounds[1] >= actAB.artboardRect[3] ) { //if top edge of dupArt is overlapping bottom edge of artboard
newAB(); //function to create artboard and position in relation to previous
actAB = docRef.artboards[actIdx];
x+= -dupArt.width + -100;
y = -50;
}
}
Note: any variables you see not declared, are declared, I just didn't include them here to try to keep this as simple as possible.
Basically the script should duplicate an existing groupItem on the existing artboard and lay them out on a new artboard from left to right, top to bottom. If one of the artpieces in a row overlaps the artboard.right then start new row. If one of the artpieces overlaps the artboard.bottom then create new artboard and start again.
If you omit the last if statement, it works sort of (theres still overlap going on). I'm assuming the script is detecting an artpiece overlapping and its saying OK, NEXT sign we'll start a new row, rather than the one thats actually started overlapping.
If you run the script as is, it starts at the first artpiece position and goes -X without creating a new row. As if the 2nd if statement is saying screw the 1st if statement.
I know the issue is with the 2nd if statement, but I can't figure out how to get them to work together as well as get the 2nd if statement to actually do whats its supposed to do. Unless I should put the if statements inside seperate functions and call them in the main loop? I'm not sure. Any help would be greatly appreciated, as always!