Notifications
Clear all

[Closed] Maxscript transformation buttons

Hello,

I am trying to learn Maxscript and I am also new to any type of programming.

I am stuck with making a script to just control the position, rotation and scale of objects.

I have 3 spinners, representing x, y, z values and 3 check buttons under it. I want to assign for the first check button a translation function, for the second rotation and for the third a scale. The translation, rotation and scale values will be set by the spinners. In this way I don’t need to create 3 sets of spinners each with a xyz value.

Here is what I have now:

group “Translate”
(
spinner TrsSpinnerX “X:” range:[-1000,1000,0] type:#float scale: 1 width:80 across: 3 align:#center
spinner TrsSpinnerY “Y:” range:[-1000,1000,0] type:#float scale: 1 width:80 align:#center
spinner TrsSpinnerZ “Z:” range:[-1000,1000,0] type:#float scale: 1 width:80 align:#center
)

on TrsSpinnerX entered do
(
$.pos.X = TrsSpinnerX.value
)

on TrsSpinnerY entered do
(
$.pos.Y = TrsSpinnerY.value
)

on TrsSpinnerZ entered do
(
$.pos.Z = TrsSpinnerZ.value
)

checkbutton TranslationB “Translation” checked:true tooltip:“Enables translation” across: 3
on TranslationB changed state do
if state == on then

else

checkbutton RotationB “Rotation” checked:false tooltip:“Enables rotation”
on RotationB changed state do
if state == on then

else

checkbutton ScaleB “Scale” checked:false tooltip:“Enables scaling”
on ScaleB changed state do
if state == on then

else

The problem I do not know what to add to the ‘if’ statement at the checkbuttons. For example, when I click on the ‘translate’ button I want this code to be enabled:

on TrsSpinnerX entered do
(
$.pos.X = TrsSpinnerX.value
)

and when I uncheck the button to disable it.

I hope you can uderstand. Any suggestions please?

2 Replies

Here is a basic snippet for you to look at.

rollout transRollout "" width:259 height:73
(
	mapped fn applyTransform obj axis val =
	(
		-- includes a catch for Bezier scale controllers
		tmPart = case of
		(
		(transRollout.TranslationB.checked):obj.position.controller
		(transRollout.RotationB.checked):obj.rotation.controller
		(transRollout.ScaleB.checked):obj.scale.controller
		)
		
		-- check for bezier scale
		if classof tmPart == bezier_scale then 
		(
			case axis of 
			(
			1:(tmPart.value = [val/100,tmPart.value[2],tmPart.value[3]])
			2:(tmPart.value = [tmPart.value[1], val/100, tmPart.value[3]])
			3:(tmPart.value = [tmPart.value[1],tmPart.value[2],val/100])
			)
		)
		else tmPart[axis].value = val
	)
	
	groupBox grpHeader "Translate" pos:[4,2] width:249 height:41 
	spinner TrsSpinnerX "X:" pos:[19,20] width:68 height:16 range:[-1000,1000,0] type:#float scale:1 across:3
	spinner TrsSpinnerY "Y:" pos:[99,20] width:68 height:16 range:[-1000,1000,0] type:#float scale:1 across:3
	spinner TrsSpinnerZ "Z:" pos:[179,20] width:68 height:16 range:[-1000,1000,0] type:#float scale:1 across:3
	checkbutton TranslationB "Translation" pos:[6,48] width:82 height:21 toolTip:"Enables translation" checked:true across:3
	checkbutton RotationB "Rotation" pos:[91,48] width:77 height:21 toolTip:"Enables rotation" checked:false across:3
	checkbutton ScaleB "Scale" pos:[170,48] width:84 height:21 toolTip:"Enables scaling" checked:false across:3

	local ckbUi = #(TranslationB,RotationB,ScaleB)
	
	on TranslationB changed state do	
	(
		if state then
		(
			for i in ckbUi where not i== TranslationB do i.checked = false
			grpHeader.text = "Translate"
		)
		else TranslationB.checked = true
		--the else here makes sure you cant disable all the checkbuttons, so one must always be enabled.
	)
			
	on RotationB changed state do	
	(
		if state then
		(
			for i in ckbUi where not i== RotationB do i.checked = false
			grpHeader.text = "Rotate"
		)
		else RotationB.checked = true			
	)
	
	on ScaleB changed state do	
	(
		if state then
		(
			for i in ckbUi where not i== ScaleB do i.checked = false
			grpHeader.text = "Scale"
		)
		else ScaleB.checked = true			
	)
	
	on TrsSpinnerX changed val do applyTransform (selection as array) 1 val	
	on TrsSpinnerY changed val do applyTransform (selection as array) 2 val	
	on TrsSpinnerZ changed val do applyTransform (selection as array) 3 val

)
createdialog transRollout

it think that the spinners have to have separate set for every transform. also all transformations has to be undoable, and work for any type of controller… is it possible?