Quick primer into computer graphics programming. Whenever you are trying to do a compound transform it is best to compose the transform onto a matrix operation. Mainly because you can specify a complex transformation in one go.
OK so no we have to compute the bounds. But then you might rotate around a arbitrary point in some case too (this makes it easy).
#target illustrator
var doc = app.activeDocument;
var sel = doc.pageItems;
var bounds = calculate_bounds(sel);
var center = [(bounds[0]+bounds[2])/2,
(bounds[1]+bounds[3])/2]
for (var i = 0; i < sel.length; i++) {
rotate_around_global_pos(sel[i], 30, center);
}
/********* Support functions *********/
function rotate_around_global_pos(obj, ang, pos) {
var rot = app.getRotationMatrix(15);
var mov = app.getTranslationMatrix(pos[0], pos[1]);
var inv = app.invertMatrix(mov);
var mtx = app.concatenateMatrix(inv, rot);
var mtx = concatenateMatrix(mtx, mov);
obj.transform(mtx, 1, 1, 1, 1, 1, Transformation.DOCUMENTORIGIN);
}
function calculate_bounds(sel){
var minX = Number.POSITIVE_INFINITY;
var maxX = Number.NEGATIVE_INFINITY;
var minY = Number.POSITIVE_INFINITY;
var maxY = Number.NEGATIVE_INFINITY;
for (i = 0; i < sel.length; i++){
var item = sel[i];
var bounds = sel[i].controlBounds;
minX = Math.min( minX, bounds[0], bounds[2] );
maxX = Math.max( maxX, bounds[0], bounds[2] );
minY = Math.min( minY, bounds[1], bounds[3] );
maxY = Math.max( maxY, bounds[1], bounds[3] );
}
return [maxX, maxY, minX, minY];
}