How to update rollout Spinner based on the materials parameter and/or object parameters changes, Callback?


#1

Hello Guys, I want to ask for some help from the community here,

I’m trying to do some advanced scripting on max but I don’t seem to find the right way to achieve what i would like to.

here is the deal, I have a rollout that replicates some material parameters, e.i (gamma, Saturation, or rotation) when I change the spinner values within the rollout they update/reflect in the material editor e.i (gamma, Saturation, or rotation), but I’m trying to update/sync my rollout spinner when changes are made into the material editor parameters and I cannot get it to work.

image

I found the functionality

when parameters (material) change do

but unfortunately, it returns any change made to any of the material parameters instead the specific one I need,

I hope someone can point me in the right direction.

Thanks to everyone that look into this Laughing


#2

I don’t understand why you are talking about (rotation)* if all parameters are related to some color value.
Anyway…

“when parameters change” handler calls if any parameter of the specifier object has been changed. Therefore, the best thing you can do is to check the parameter you are monitoring and update its UI controller if necessary.

try(destroydialog rol) catch()
rollout rol "Test" width:191
(
	group "Diffuse Color: "
	(
		spinner r_sp "R:" type:#float range:[0,255,0] fieldwidth:54 align:#left offset:[8,0] across:2
		spinner h_sp "H:" type:#float range:[0,255,0] fieldwidth:54 align:#right offset:[4,0]
		spinner g_sp "G:" type:#float range:[0,255,0] fieldwidth:54 align:#left offset:[8,0] across:2
		spinner s_sp "S:" type:#float range:[0,255,0] fieldwidth:54 align:#right offset:[4,0]
		spinner b_sp "B:" type:#float range:[0,255,0] fieldwidth:54 align:#left offset:[8,0] across:2
		spinner v_sp "V:" type:#float range:[0,255,0] fieldwidth:54 align:#right offset:[4,0]
	)

	local mat 
	local change_handler 

	fn check_set sp v = if (sp.value != v) do sp.value = v
	
	fn updateMaterialParams = if iskindof mat Standard do
	(
		c = mat.DiffuseColor
		check_set r_sp c.r
		check_set g_sp c.g
		check_set b_sp c.b

		check_set h_sp c.h
		check_set s_sp c.s
		check_set v_sp c.v
	)
	
	on rol close do
	(
		try (deletechangehandler change_handler) catch()
	)
	on rol open do
	(
		meditmaterials[1] = mat = Standard name:#TestMaterial 
		change_handler = when parameters mat change do updateMaterialParams()
		updateMaterialParams()
	)
)
createdialog rol

/*

rol.mat
rol.mat.diffusecolor = orange
max undo

rol.mat.diffusecolor = green
rol.mat.diffusecolor = (color 10 11 12)
rol.mat.diffusecolor.b = 120

max undo

*/

#3

Hello DenisT, thanks for your answer, I apologize for the typo, you are correct, I was just trying to use (rotation) as an example of a parameter, but I have fixed it to make it more clear.

Thanks for your script example really advance things, especially with the color palette i wouldn’t know how to archive that for sure, really insightful, Thanks.

I was on the verge of a similar solution, But I was trying to find a more specific call to each parameter rather than all parameters using “when parameters mat change do” since by using this, I will get a callback every time any of the parameters in a material change, and that’s a lot of feedback…

Right now I got something similar working and I was able to link each parameter i wanted to the Rollout control i wanted it, but as I said, there is a lot of wasted feedback in the background every time that any other parameter i don’t need changes.

Thanks again… I would definitely use this case for the color picker.