Notifications
Clear all

[Closed] Can not read a assigned Variable

Hi to all
I have a code and I do not understand why the Variable in lines 22,24,26 (refObjX and refObjY and refObjZ) are working but when I want to use these Variables in line 58 does not work and there is an Error that say “can not convert type:float”

Can you please tell me my mistake

I am noob in Maxscript

rollout animateObj “Animate OBJs to a Special Position” width:320 height:230
(
– UI Group Box
groupBox ‘grpOptions’ “Options” pos:[10,10] width:300 height:50 align:#left
groupBox ‘grpPosition’ “Set New OBJs Position” pos:[10,65] width:300 height:105 align:#left

-- UI Check Box
checkbox 'chk1' "Auto Keyframe Length" pos:[40,27] width:140 height:25 checked:true align:#left
checkbox 'chk2' "From F0" pos:[185,27] width:90 height:25 checked:true align:#left

-- UI Text Box
editText 'edtx' "X: " pos:[45,93] width:70 height:20 align:#left
editText 'edty' "Y: " pos:[125,93] width:70 height:20 align:#left
editText 'edtz' "Z: " pos:[205,93] width:70 height:20 align:#left

-- UI Buttons
pickButton 'btn1' "Get Position" pos:[60,131] width:200 height:25 align:#left
button 'btn2' "Animate it !" pos:[108,185] width:100 height:30 align:#left

on btn1 picked refobj do (
refObjX = refobj.pos.x – this Variable
edtx.text = refObjX as string

	refObjY = refobj.pos.y                     -- this Variable        
	edty.text = refObjY as string
	
	refObjZ = refobj.pos.z                     -- this Variable 
	edtZ.text = refObjZ as string

	btn1.text = refobj.name

	print refObjX
	print refObjy
	print refObjz
	)

on btn2 pressed do (
if (selection.count == 0) do (messagebox “Please select a Group!”)
if (selection.count != 0) do (
countGroups = (for grp in selection where (isGroupHead grp == true) collect grp)
framelength = countGroups.count*2
if chk1.state == true do (
animationRange = interval 0 framelength
print countGroups.count
print framelength
)

if chk2.state == true do (
		sliderTime = 0f	
		)
	
for obj in selection where (isgrouphead obj) and not (isGroupMember obj) do (
		oldpos = obj.pos
		max tool animmode
		set animate on
		obj.pos = oldpos
		sliderTime += 1
		obj.pos = [refObjX,refObjY,refObjZ]    -- here does not work
		print obj.pos
		sliderTime += 1
		obj.pos = oldpos
		print obj.pos
		)

(
max tool animmode
set animate off
sliderTime = 0f
)
)
)
)
CreateDialog animateObj “Animate OBJs to a Special Position” width:320 height:230

2 Replies

Because the variables exist only on btn1 picked event.
Try this:

rollout animateObj "Animate OBJs to a Special Position" width:320 height:230
(
	local refObjX = undefined
	local refObjY = undefined
	local refObjZ = undefined
	
	
	groupBox grpOptions "Options" pos:[10,10] width:300 height:50 align:#left
	groupBox grpPosition "Set New OBJs Position" pos:[10,65] width:300 height:105 align:#left

	-- UI Check Box
	checkbox chk1 "Auto Keyframe Length" pos:[40,27] width:140 height:25 checked:true align:#left
	checkbox chk2 "From F0" pos:[185,27] width:90 height:25 checked:true align:#left

	-- UI Text Box
	editText edtx "X: " pos:[45,93] width:70 height:20 align:#left
	editText edty "Y: " pos:[125,93] width:70 height:20 align:#left
	editText edtz "Z: " pos:[205,93] width:70 height:20 align:#left

	-- UI Buttons
	pickButton btn1 "Get Position" pos:[60,131] width:200 height:25 align:#left
	button btn2 "Animate it !" pos:[108,185] width:100 height:30 align:#left

	on btn1 picked refobj do 
	(
		refObjX = refobj.pos.x -- this Variable
		edtx.text = refObjX as string

		refObjY = refobj.pos.y                     -- this Variable        
		edty.text = refObjY as string
		
		refObjZ = refobj.pos.z                     -- this Variable 
		edtZ.text = refObjZ as string

		btn1.text = refobj.name

		print refObjX
		print refObjy
		print refObjz
	)

	on btn2 pressed do 
	(
		if (selection.count == 0) do (messagebox "Please select a Group!")
		if (selection.count != 0) do (
		countGroups = (for grp in selection where (isGroupHead grp == true) collect grp)
		framelength = countGroups.count*2
		if chk1.state == true do 
		(
			animationRange = interval 0 framelength
			print countGroups.count
			print framelength
		)

		if chk2.state == true do 
		(
			sliderTime = 0f	
		)
			
		for obj in selection where (isgrouphead obj) and not (isGroupMember obj) do 
		(
			oldpos = obj.pos
			max tool animmode
			set animate on
			obj.pos = oldpos
			sliderTime += 1
			obj.pos = [refObjX,refObjY,refObjZ]    -- here does not work
			print obj.pos
			sliderTime += 1
			obj.pos = oldpos
			print obj.pos
		)

		(
			max tool animmode
			set animate off
			sliderTime = 0f
		)
	)
	)
)
CreateDialog animateObj "Animate OBJs to a Special Position" width:320 height:230

Thank you so much. Perfect