Hi,
I can see a workaround like this:
1. prepare measurments and zeroPoint in your Doc
to calculate corner's we need to use page.bounds (+/- particular margin)
and page.bounds are returned in POINTS
2. make sure a doc IS NOT facing pages
to simplify move(to:[x,y]) procedure
3. get IDMS into array
alike you did it
4. iterate through this array, count steps
shift elements - so array length decreases
5. set last page as a target and place current snippet to this page (some default location, no matter where)
6. check current step value and switch corner calculation using 'case: step'
assumings: originally snippet's absoluteRotationAngle = 0
according to above we need to calculate [x,y] values as a target for moving snippet's LeftUp corner.
7. if step%4 == 3 check folderIn length
if NOT END -- add a new page and update cPage and margins vars
8. move current snippet to a proper point
9. next step
code to check:
var mDoc = app.activeDocument;
mDoc.documentPreferences.facingPages = false;
app.transformPreferences.transformationsAreTotals = true;
with (mDoc.viewPreferences) {
horizontalMeasurementUnits = MeasurementUnits.POINTS;
verticalMeasurementUnits = MeasurementUnits.POINTS;
rulerOrigin = RulerOrigin.PAGE_ORIGIN;
}
mDoc.zeroPoint = [0,0];
//|||||||||||||||||||||||||||||||||||||||||||||||
var
myFolder = File("D:\\PNG"),
folderIn = myFolder.getFiles("*.idms"),
cFile,
cPage = mDoc.pages[-1],
margins = detectMargins(cPage),
step = -1, inSnp, cCorner,
mSize = {
w: 0,
h: 0
};
while ( cFile = folderIn.shift() ) {
step++;
inSnp = cPage.place(cFile)[0];
mSize.w = inSnp.geometricBounds[3] - inSnp.geometricBounds[1];
mSize.h = inSnp.geometricBounds[2] - inSnp.geometricBounds[0];
switch (step%4) {
case 0:
cCorner = [
margins.left,
margins.top,
];
break;
case 1:
cCorner = [
margins.left,
margins.bottom - mSize.h,
];
break;
case 2:
cCorner = [
margins.right - mSize.w,
margins.top
];
break;
case 3:
cCorner = [
margins.right - mSize.w,
margins.bottom - mSize.h,
];
if (!folderIn.length) break;
cPage = mDoc.pages.add(LocationOptions.AT_END);
margins = detectMargins(cPage);
}
inSnp.move(cCorner);
}
function detectMargins(mPage) {
return new Object ({
top: mPage.marginPreferences.top,
left: mPage.marginPreferences.left,
bottom: mPage.bounds[2] - mPage.marginPreferences.bottom,
right: mPage.bounds[3] - mPage.marginPreferences.right
});
}
Jarek