How to code Align Selection (max's and min's)

How to code Align Selection (max's and min's)

Anonymous
Not applicable
1,647 Views
4 Replies
Message 1 of 5

How to code Align Selection (max's and min's)

Anonymous
Not applicable

I have multiple cylinders 'surface constrained' to a sphere.

 

I then have multiple planes I want to align to their relevant cylinders, nominating Minimums and Maximums independently for the XYZ axis - as I would when using Align Selection dialog.

 

How do I achieve this with MaxScript?

 

I've tried PlaneObject.transform = CylinderObject.transform

 

But this performs a rotation also, and doesn't give me the ability to set Maximums or Minimums

 

 

thanks 

0 Likes
Accepted solutions (1)
1,648 Views
4 Replies
Replies (4)
Message 2 of 5

Swordslayer
Advisor
Advisor

Just guessing the exact outcome so I might be a little bit off in my assumptions, I guess you might wanna use object's bounding box, right? Each node (and selection of nodes, for that matter) exposes .min, .max and .center property, so some variant of planeObj.pos = cylObj.min might do the trick.

0 Likes
Message 3 of 5

Anonymous
Not applicable

hi @Swordslayer thanks for the hint but I'm having difficulty getting it to work. 

 

I can dictate the properties of the cylinder ok i.e. cylinder.max .min etc

 

But I'm getting a runtime error when i do plane.max to match them up i.e. plane.max = cylinder.max

 

Also I'm having difficulty getting the rotations to line up: plane to cylinder - i think because the cylinder is surface contained to the Sphere 

0 Likes
Message 4 of 5

drew_avis
Autodesk
Autodesk

The min and max properties of a node are read-only, but you could try setting the center and see if that does what you're looking for:

 

$Plane001.center = $Cylinder001.max


Drew Avis
Content Experience Designer
Message 5 of 5

Anonymous
Not applicable
Accepted solution

thanks @drew_avis but as the Cylinder is surface constrained to the Sphere - using its XYZ's to set to the Plane doesn't work, since the Cylinder is no longer at that location in the view - it's over on the Sphere.

 

So I've figured out another approach: get the controller settings of the Cylinder and apply them to the Plane. I did some digging through the forum and found this post which helped.

 

Cheers thanks again for helping, it helped in ruling out options and pushed me to find an alternative!

 

0 Likes