Skip to main content
Inspiring
July 12, 2018
Answered

Auto vertical and horizontal Align script

  • July 12, 2018
  • 3 replies
  • 10442 views

Hi,

First of all - I'v maded few hours of search (this forum and google).

I was found script which is almost doing what i want: Peter Kahrel -- Free script | Align objects

But i would like to have easier (faster) scirpt:

What i would like to have:

I would like select 2 objects - and by one click align them vertical and horizontl.

Default using Adobe tool i must always make two clicks for both options.

Do you know maybe how i can do that?

Best Regards

Jarek

This topic has been closed for replies.
Correct answer jarosławz53072541

Hi,

Thanks to Peter Kahrel who made this one  Peter Kahrel -- Free script | Align objects

I was ask him is there any chance to make modification.

So he did it - and i'm very helpfoul for him.

So - what i maded with this? I was created shortcut CTRL+SHIFT+C and attached script:

And now what i have ?:D

When i select two object's i can simply pres shorcut described above and have aligned two objects

Mr. Peter Kharel - thank you for all - Your are Amazing!!!

(BTW: First selected object is "key object")

// DESCRIPTION Align frames CorelDraw-style: last selected frame is target

// Peter Kahrel

var obj = app.selection;

if( obj.length < 2 ) {

errorM('Select at least two objects');

}

function errorM( m ){

alert( m );

exit()

}

function getPosition( o, pos ) {

switch( pos ) {

case 'top' : return o.geometricBounds[0];

case 'left' : return o.geometricBounds[1];

case 'bottom' : return o.geometricBounds[2];

case 'right' : return o.geometricBounds[3];

case 'hcentre' : return o.geometricBounds[1] +

((o.geometricBounds[3] - o.geometricBounds[1]) / 2);

case 'vcentre' : return o.geometricBounds[0] +

((o.geometricBounds[2] - o.geometricBounds[0]) / 2);

}

}

function align_hor( obj, source_align, target_align ){

var target = getPosition( obj[0], target_align )

for( var i = 1; i < obj.length; i++ ) {

obj.move( undefined, [target - getPosition(obj,source_align), 0], true );

}

}

function align_vert( obj, source_align, target_align ){

var target = getPosition( obj[0], target_align )

for( var i = 1; i < obj.length; i++ ) {

obj.move( undefined,

[0, target - getPosition(obj,source_align)], true )

}

}

function alignFrames (type) {

switch (type) {

// horizontal alignment

case 'RL' : align_hor( obj, 'right', 'left'); break;

case 'RC' : align_hor( obj, 'right', 'hcentre'); break;

case 'RR' : align_hor( obj, 'right', 'right'); break;

case 'CL' : align_hor( obj, 'hcentre', 'left'); break;

case 'CCH' : align_hor( obj, 'hcentre', 'hcentre'); break;

case 'CR' : align_hor( obj, 'hcentre', 'right'); break;

case 'LL' : align_hor( obj, 'left', 'left'); break;

case 'LC' : align_hor( obj, 'left', 'hcentre'); break;

case 'LR' : align_hor( obj, 'left', 'right'); break;

// vertical alignment

case 'BT' : align_vert( obj, 'bottom', 'top'); break;

case 'BC' : align_vert( obj, 'bottom', 'vcentre'); break;

case 'BB' : align_vert( obj, 'bottom', 'bottom'); break;

case 'CT' : align_vert( obj, 'vcentre', 'top'); break;

case 'CCV' : align_vert( obj, 'vcentre', 'vcentre'); break;

case 'CB' : align_vert( obj, 'vcentre', 'bottom'); break;

case 'TT' : align_vert( obj, 'top', 'top'); break;

case 'TC' : align_vert( obj, 'top', 'vcentre'); break;

case 'TB' : align_vert( obj, 'top', 'bottom'); break;

default : errorM('Illegal input.')

}

}

alignFrames ('CCH');

alignFrames ('CCV');

//~ function alignType(){

//~ var dlg = app.dialogs.add( { name: 'Align' });

//~ with( dlg.dialogColumns.add() )

//~ with( borderPanels.add() )

//~ var userSelect = textEditboxes.add( { editContents : 'CCH' } );

//~ if( dlg.show() )

//~ {

//~ var temp = userSelect.editContents;

//~ dlg.destroy();

//~ return temp;

//~ }

//~ else

//~ {

//~ dlg.destroy();

//~ exit();

//~ }

//~ }

So we can close ticket as it is fixed

3 replies

Jongware
Community Expert
Community Expert
July 13, 2018

jarosławz53072541  wrote

I would like select 2 objects - and by one click align them vertical and horizontl.

So they end up on top of each other, centered on the center point? If that is not what you mean, show a "before/after" image.

FRIdNGE
July 13, 2018

Hi,

Maybe I'm wrong! …

According to me, there're 9 configurations [alignments, no distributions]!

So 9 simplistic 2-lines scripts, whose name is associated to a number of the keypad!

7 8 9

4 5 6

1 2 3

… so, e.g., "horizontal-centers alignment + vertical-centers alignment" would be:

app.activeDocument.align (app.selection, AlignOptions.HORIZONTAL_CENTERS);

app.activeDocument.align (app.selection, AlignOptions.VERTICAL_CENTERS);

Its name: 5_H-Center--V-Center.jsx

I could give you the 8 other scripts but I'm too lazy for that!

Welcome to the party!

Best,

Michel, For FRIdNGE

Inspiring
July 13, 2018

Here is the script for AppleScript:

tell application "Adobe InDesign CC 2018"

  set selList to selection --assumes more than one item selected

  tell document 1

  align align distribute items selList align option horizontal centers

  align align distribute items selList align option vertical centers

  end tell

end tell

Put the script with your scripts in the Scripts panel and give it a keyboard shortcut (maybe Command + Shift + A) for one-stroke functionality. Keyboard Shortcuts are found under Edit in InDesign's menu.

Inspiring
July 16, 2018

So this might by good script - but in windows isn't work

Here is the script for AppleScript:

tell application "Adobe InDesign CC 2018"

  set selList to selection --assumes more than one item selected

  tell document 1

  align align distribute items selList align option horizontal centers

  align align distribute items selList align option vertical centers

  end tell

end tell

Put the script with your scripts in the Scripts panel and give it a keyboard shortcut (maybe Command + Shift + A) for one-stroke functionality. Keyboard Shortcuts are found under Edit in InDesign's menu.

BarlaeDC
Community Expert
Community Expert
July 12, 2018

Hi,

I know this is not a scripting solution but in CC 2018 (I haven't checked other versions) if you use quick apply - it defaults to the align options when you have 2 or more objects selected, that is just Cmd(Ctrl) + Return and then type or click to get the one you want, I don't' see a script making it much faster than that, but it maybe someone on here has a faster solution.

Regards

Malcolm