• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Auto vertical and horizontal Align script

Community Beginner ,
Jul 12, 2018 Jul 12, 2018

Copy link to clipboard

Copied

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

TOPICS
Scripting

Views

8.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Jul 15, 2018 Jul 15, 2018

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")

//

...

Votes

Translate

Translate
Community Expert ,
Jul 12, 2018 Jul 12, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jul 13, 2018 Jul 13, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 13, 2018 Jul 13, 2018

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 15, 2018 Jul 15, 2018

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 14, 2018 Jul 14, 2018

Copy link to clipboard

Copied

https://forums.adobe.com/people/Michel+%5BFRIdNGE%5D  wrote

… Welcome to the party!

Hi Michel,

see also into method distribute() and property selectionKeyObject of object Document.

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 15, 2018 Jul 15, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 16, 2018 Jul 16, 2018

Copy link to clipboard

Copied

It's greate! but - objects are moving from place.

I was posted script maded by: Peter Kahrel​ which is more useful.

But thank you for advice It's pretty nice to recive some help.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 16, 2018 Jul 16, 2018

Copy link to clipboard

Copied

jarosÅ‚awz53072541  wrote

… but - objects are moving from place.

Hi Jaroslaw,

they do because there is no selectionKeyObject in the selection.

And it is also not defined in the script by Michel. Assumption: Neither it is defined by the user, you.

Michel's script run on two objects selected where no selectionKeyObject is applied to the selection:

Align-CENTER-CENTER-No-selectionKeyObject-1.PNG

Align-CENTER-CENTER-No-selectionKeyObject-2.PNG

If Michel's script would work with selectionKeyObject and selectionKeyObject would have been defined by the user with an extra click:

Align-CENTER-CENTER-selectionKeyObject-applied-1.PNG

Align-CENTER-CENTER-selectionKeyObject-applied-2.PNG

Note: method align() has 4 arguments that are relevant if there is a selectionKeyObject.

If there is and you are using Michel's script it will throw an error message.

Here a different version of Michel's script that is working with or without a selectionKeyObject:

( function()

{

    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;

    app.doScript

    (

        alignCenterCenter,

        ScriptLanguage.JAVASCRIPT,

        [],

        UndoModes.ENTIRE_SCRIPT,

        "Align Selection Center-Center | SCRIPT"

    );

    function alignCenterCenter()

    {

        if( app.documents.length == 0 ){ return };

        if( app.selection.length < 2 ){ return };

       

        var doc = app.activeDocument;

       

        if( doc.selectionKeyObject == null )

        {

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

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

            return;

        }

       

        doc.align( app.selection , AlignOptions.HORIZONTAL_CENTERS , AlignDistributeBounds.KEY_OBJECT , doc.selectionKeyObject );

        doc.align( app.selection , AlignOptions.VERTICAL_CENTERS , AlignDistributeBounds.KEY_OBJECT , doc.selectionKeyObject );

    };

}() )

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 16, 2018 Jul 16, 2018

Copy link to clipboard

Copied

Thank you But Peter script automatically set "key object" as first selected item.

So there isn't necessary to choose from panel align "key object" simply this making script maded by Peter.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 16, 2018 Jul 16, 2018

Copy link to clipboard

Copied

LATEST

Hi Jaroslaw,

the one above could be useful if you selected all objects you want to align and did not make up your mind or you changed your mind on the object you want the others align to. 🙂

Best,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 13, 2018 Jul 13, 2018

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines