Тебя о финансовом эквиваленте спрашивают.Часа два с тестированием в разных условиях.
for(var i=0;i<app.selection.length;i++)
try{
var currObj = app.selection[i];
currObj.move([currObj.parentPage.bounds[3]/2+currObj.parentPage.bounds[1]/2-(currObj.geometricBounds[3]-currObj.geometricBounds[1])/2,
currObj.parentPage.bounds[0]/2+currObj.parentPage.bounds[2]/2-(currObj.geometricBounds[2]-currObj.geometricBounds[0])/2])
}catch(e){}
var grBounds = app.selection[0].geometricBounds;
for(var i=1;i<app.selection.length;i++)
try{
var currObj = app.selection[i];
grBounds[0]=Math.min(grBounds[0],currObj.geometricBounds[0]);
grBounds[1]=Math.min(grBounds[1],currObj.geometricBounds[1]);
grBounds[2]=Math.max(grBounds[2],currObj.geometricBounds[2]);
grBounds[3]=Math.max(grBounds[3],currObj.geometricBounds[3]);
}catch(e){}
var dx = currObj.parentPage.bounds[3]/2+currObj.parentPage.bounds[1]/2 - grBounds[3]/2-grBounds[1]/2;
var dy = currObj.parentPage.bounds[0]/2+currObj.parentPage.bounds[2]/2 - grBounds[0]/2-grBounds[2]/2;
for(var i=0;i<app.selection.length;i++)
try{
var currObj = app.selection[i];
currObj.move(undefined,[dx,dy])
}catch(e){}
#target indesign
function getSelectionBounds () {
var bounds = app.selection[0].geometricBounds;
for (var i = 1; i < app.selection.length; i++) {
var b = app.selection[i].geometricBounds;
if (b[0] < bounds[0]) {
bounds[0] = b[0];
}
if (b[1] < bounds[1]) {
bounds[1] = b[1];
}
if (b[2] > bounds[2]) {
bounds[2] = b[2];
}
if (b[3] > bounds[3]) {
bounds[3] = b[3];
}
}
return bounds;
}
function getCenter (bounds) {
return [(bounds[1] + (bounds[3] - bounds[1]) / 2), (bounds[0] + (bounds[2] - bounds[0]) / 2)];
}
function moveSelection () {
var step = eval(arguments[0][0]);
for (var i = 0; i < app.selection.length; i++) {
app.selection[i].move(undefined, step);
}
}
function main () {
if (app.documents.length == 0) {
return false;
}
if (app.selection.length == 0) {
return false;
}
var page = app.activeWindow.activePage;
var bounds = getSelectionBounds();
var sc = getCenter(bounds);
var pc = getCenter(page.bounds);
var step = [pc[0] - sc[0], pc[1] - sc[1]];
app.doScript(moveSelection, ScriptLanguage.JAVASCRIPT, [step.toSource()], UndoModes.FAST_ENTIRE_SCRIPT, 'Center Selection');
}
main();
вернее вот так
Код:var grBounds = app.selection[0].geometricBounds; for(var i=1;i<app.selection.length;i++) try{ var currObj = app.selection[i]; grBounds[0]=Math.min(grBounds[0],currObj.geometricBounds[0]); grBounds[1]=Math.min(grBounds[1],currObj.geometricBounds[1]); grBounds[2]=Math.max(grBounds[2],currObj.geometricBounds[2]); grBounds[3]=Math.max(grBounds[3],currObj.geometricBounds[3]); }catch(e){} var dx = currObj.parentPage.bounds[3]/2+currObj.parentPage.bounds[1]/2 - grBounds[3]/2-grBounds[1]/2; var dy = currObj.parentPage.bounds[0]/2+currObj.parentPage.bounds[2]/2 - grBounds[0]/2-grBounds[2]/2; for(var i=0;i<app.selection.length;i++) try{ var currObj = app.selection[i]; currObj.move(undefined,[dx,dy]) }catch(e){}
Код:#target indesign function getSelectionBounds () { var bounds = app.selection[0].geometricBounds; for (var i = 1; i < app.selection.length; i++) { var b = app.selection[i].geometricBounds; if (b[0] < bounds[0]) { bounds[0] = b[0]; } if (b[1] < bounds[1]) { bounds[1] = b[1]; } if (b[2] > bounds[2]) { bounds[2] = b[2]; } if (b[3] > bounds[3]) { bounds[3] = b[3]; } } return bounds; } function getCenter (bounds) { return [(bounds[1] + (bounds[3] - bounds[1]) / 2), (bounds[0] + (bounds[2] - bounds[0]) / 2)]; } function moveSelection () { var step = eval(arguments[0][0]); for (var i = 0; i < app.selection.length; i++) { app.selection[i].move(undefined, step); } } function main () { if (app.documents.length == 0) { return false; } if (app.selection.length == 0) { return false; } var page = app.activeWindow.activePage; var bounds = getSelectionBounds(); var sc = getCenter(bounds); var pc = getCenter(page.bounds); var step = [pc[0] - sc[0], pc[1] - sc[1]]; app.doScript(moveSelection, ScriptLanguage.JAVASCRIPT, [step.toSource()], UndoModes.FAST_ENTIRE_SCRIPT, 'Center Selection'); } main();
Да любую, насколько скрипт помог. Тайна вклада гарантируется!Назовите сумму
один без скрипта не проще отцентровать?
Да любую, насколько скрипт помог. Тайна вклада гарантируется!
Код:#target indesign function getSelectionBounds () { var bounds = app.selection[0].geometricBounds; for (var i = 1; i < app.selection.length; i++) { var b = app.selection[i].geometricBounds; if (b[0] < bounds[0]) { bounds[0] = b[0]; } if (b[1] < bounds[1]) { bounds[1] = b[1]; } if (b[2] > bounds[2]) { bounds[2] = b[2]; } if (b[3] > bounds[3]) { bounds[3] = b[3]; } } return bounds; } function getCenter (bounds) { return [(bounds[1] + (bounds[3] - bounds[1]) / 2), (bounds[0] + (bounds[2] - bounds[0]) / 2)]; } function moveSelection () { var step = eval(arguments[0][0]); for (var i = 0; i < app.selection.length; i++) { app.selection[i].move(undefined, step); } } function main () { if (app.documents.length == 0) { return false; } if (app.selection.length == 0) { return false; } var page = app.activeWindow.activePage; var bounds = getSelectionBounds(); var sc = getCenter(bounds); var pc = getCenter(page.bounds); var step = [pc[0] - sc[0], pc[1] - sc[1]]; app.doScript(moveSelection, ScriptLanguage.JAVASCRIPT, [step.toSource()], UndoModes.FAST_ENTIRE_SCRIPT, 'Center Selection'); } main();
Коллеги, подсобите плиз)
Какие строчки нужно убрать чтобы центрировалось только по вертикали?)
var step = [undefined, pc[1] - sc[1]];
Олег, спасибо!var step = [undefined, pc[1] - sc[1]];
#target indesign
function getSelectionBounds () {
var bounds = app.selection[0].geometricBounds;
for (var i = 1; i < app.selection.length; i++) {
var b = app.selection[i].geometricBounds;
if (b[0] < bounds[0]) {
bounds[0] = b[0];
}
if (b[1] < bounds[1]) {
bounds[1] = b[1];
}
if (b[2] > bounds[2]) {
bounds[2] = b[2];
}
if (b[3] > bounds[3]) {
bounds[3] = b[3];
}
}
return bounds;
}
function getCenter (bounds) {
return [(bounds[1] + (bounds[3] - bounds[1]) / 2), (bounds[0] + (bounds[2] - bounds[0]) / 2)];
}
function moveSelection () {
var step = eval(arguments[0][0]);
for (var i = 0; i < app.selection.length; i++) {
app.selection[i].move(undefined, step);
}
}
function main () {
if (app.documents.length == 0) {
return false;
}
if (app.selection.length == 0) {
return false;
}
var page = app.activeWindow.activePage;
var bounds = getSelectionBounds();
var sc = getCenter(bounds);
var pc = getCenter(page.bounds);
var step = [undefined, pc[1] - sc[1]];
app.doScript(moveSelection, ScriptLanguage.JAVASCRIPT, [step.toSource()], UndoModes.FAST_ENTIRE_SCRIPT, 'Center Selection');
}
main();
Вместо undefined ноль должен быть. Это я протупил.