Page 1 of 1

[How To] Align objects through script

Posted: Sat Feb 15, 2014 8:03 pm
by palanolho
Greetings everyone,

I'm struggling with something and maybe someone has an idea how I can pull this one off.

I have 2 objects (lets say 2 rectangles) and I need to align one of them (vertically or horizontally) relatively to the other one.

Anyone know how this can be done? using the tools it would be easy but, how can this be done using a script?

Many thanks in advance
- Miguel Pinto

Re: [How To] Align objects through script

Posted: Sat Feb 15, 2014 10:22 pm
by SparkOut
Hi Miguel,
The left, right, top, bottom, width, height, rect and loc of an object are all settable properties.

If you have two rectangles at the correct vertical position on the card and want to align the two to the same horizontal position you can do something like

Code: Select all

set the left of graphic "rectangle2" to the left of graphic "rectangle1"
If they are different widths and you want to align them according to the centre you will have to do a little construction of the new co-ordinates

Code: Select all

put item 1 of the loc of graphic "rectangle1" into item 1 of tNewLoc
put item 2 of the loc of graphic "rectangle2" into item 2 of tNewLoc
set the loc of graphic "rectangle2" to tNewLoc
Hope that helps

Re: [How To] Align objects through script

Posted: Sat Feb 15, 2014 10:48 pm
by palanolho
Cool, It was exactly this I was looking for.

I had read something about the left, right, etc... but didn't know that I could use it like that

Many thanks!
- Miguel