PISTON MAKER

Piston maker creates a piston assembly from two geometry objects. It creates a point helper at the pivot of each object, and parents that object to itself. Then using lookat controlers it sets each point to orient towards the other.

If you move these points around the objects stay oriented as if they were a piston.

CODE

try
(
global switchVariable
switchVariable = False

if selection.count != 2 then
(
messagebox("You must select Two (2) objects")
)
else
(

hydPoint01 = Point pos:[0,0,0] Box:off cross:on wirecolor:red
hydPoint02 = Point pos:[0,0,0] Box:off cross:on wirecolor:red

for i in 1 to selection.count do
(
if switchVariable != true then
(

hydPoint01.transform = selection[i].transform
selection[i].parent = hydPoint01
selection[i].rotation.controller = rotation_list ()
selection[i].rotation.controller.Available.controller = LookAt_Constraint () a
selection[i].rotation.controller.LookAt_Constraint.constraints.appendTarget hydPoint02 100
selection[i].rotation.controller.LookAt_Constraint.controller.target_axis = 2
selection[i].rotation.controller.LookAt_Constraint.controller.upnode_axis = 1
selection[i].rotation.controller.LookAt_Constraint.controller.StoUP_axis = 1
selection[i].rotation.controller.LookAt_Constraint.controller.viewline_length_abs = off
selection[i].rotation.controller.LookAt_Constraint.controller.lookat_vector_length = 0


switchVariable = true
)
else
(

hydPoint02.transform = selection[i].transform
selection[i].parent = hydPoint02
selection[i].rotation.controller = rotation_list ()
selection[i].rotation.controller.Available.controller = LookAt_Constraint () a
selection[i].rotation.controller.LookAt_Constraint.constraints.appendTarget hydPoint01 100
selection[i].rotation.controller.LookAt_Constraint.controller.target_axis = 2
selection[i].rotation.controller.LookAt_Constraint.controller.upnode_axis = 1
selection[i].rotation.controller.LookAt_Constraint.controller.StoUP_axis = 1
selection[i].rotation.controller.LookAt_Constraint.controller.viewline_length_abs = off
selection[i].rotation.controller.LookAt_Constraint.controller.lookat_vector_length = 0
)
)
)
)catch(messagebox("You must select Two (2) objects"))