newbie, simple path constraint script having problems with

Hi
I am trying to learn a bit of maxscript so i thought i would just do a simple path constraint script with a rollout!!
i am having problems getting the "go" button to add the "track" into the path contraint any help or advice would be great.

rollout Thomas "Thomas Train" width:162 height:169
(
pickbutton btn "--pick front train--" pos:[19,63] width:130 height:25
pickbutton btn9 "--pick track--" pos:[19,16] width:131 height:26
button btn3 "Go" pos:[22,109] width:128 height:29

--variables, the axis is 0-X axis, and thepath = the slinethe train will go on
--pick the train
on btn picked obj do
(
btn.text = obj.name
Thomas = obj
--if obj != undefined do
--Thomas.wirecolor = red

)
--pick the track
on btn9 picked obj2 do
(
btn9.text = obj2.name
thepath = obj2
--if obj2 != undefined do
--plastictrack.wirecolor = red

)

on btn3 pressed do
(

--select train named Thomas and apply a path contraint to the position controller
Thomas.pos.controller = Path_Constraint ()
Thomas.pos.controller.follow = on
Thomas.pos.controller.axis = 0
theConstraint = path_constraint()
--need to apply -btn9- the spline to the path constraint
--
Thomas.position.controller = theConstraint
theConstraint.path = thepath

)
)
(

createdialog Thomas
)

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
barigazy's picture

like this

try(destroydialog ::Tomas)catch()
rollout Thomas "Thomas Train" width:162 height:169
(
	local theTrain, thePath
	fn filtShape spl = isKindOf spl SplineShape or isKindOf spl Line
	pickbutton pb_path "--pick track--" pos:[5,5] width:120 height:20 filter:filtShape	
	pickbutton pb_train "--pick front train--" pos:[5,30] width:120 height:20
	button btn_go "GO" pos:[5,55] width:120 height:20
	on pb_train picked obj do
	(
		if isValidNode obj do (pb_train.text = obj.name ; theTrain = obj)
	)
	on pb_path picked obj2 do 
	(
		if isValidNode obj2 do (pb_path.text = obj2.name ; thePath = obj2)
	)
	on btn_go pressed do
	(
		if isValidNode theTrain and isValidNode thePath then
		(
			theTrain.pos.controller = Path_Constraint follow:on axis:0 path:thePath
		)
		else messagebox "Check pickbuttons first!"
	)
)
createdialog Thomas 130 80 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)

bga

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.