Getting a spinner value to change a value in a script.

Hi guys.

I'd like to know how to use the value of a spinner to change something in a script.

So when a user changes a spinner value, that vale is used to adjut the settings of the rest of the script when a button is pressed.

It's for my Multi/Sub-Object script and i'd like a spinner so that the user can select how many sub materials they want. I've got the spinner in the UI, i just can't figure out how to take the spinner value and put it into the property for the number of materials.......It seems simple but everything i've tried doesn't work.

Cheers.

Comments

Comment viewing options

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

haha no need to do so really

haha no need to do so really :P but if you want to, its lowercase "br0t" ;)
the interface is a lot better now! nothing to complain

Never get low & slow & out of ideas

Script_Butler's picture

Right you are!

Hopefully I'll have some time soon to try scripting the different colour ideas i have.

Watch this space!

Cheers.

Script_Butler

br0t's picture

glad I could help! Its not

glad I could help! Its not that long ago I struggled with these things, this forum is great to learn MXS

Never get low & slow & out of ideas

Script_Butler's picture

Big help

It has been a big help to me, and it's users like yourself that are the key. People that don't mind helping out with really simple questions!

I'd like to put a credit for you no my script. See the below code, at the moment it's just a thank-you with a label. Feel free to change it to a link to yourself of change it to whatever you want it to be. Once you've changed it i will upload the latest version to the Scripts part on here!

I've had a slight adjustment this morning putting the seperate material types in their own rollouts, and added the MentalRay code. I think it's a bit more user friendly now. Let me know what you think or if you think it could be tweaked to be more user friendly still

Thanks again for your input.

--try killing the old dialog, if there is one
try(closeRolloutFloater rof)catch()
 
rollout a "Standard Multi/Sub-Object" width:250 height:400
(
	editText basename "Material Base Name: " pos:[25,4] width:178 height:16 text:"myMaterial"
	spinner stdnum_mtl "Standard Sub Mtl count" pos:[35,26] width:164 height:16 range:[2,100,10] type:#integer fieldwidth:40
	button btn_1 "Create" pos:[20,47] width:200 height:20
 
	on btn_1 pressed do
	(
		mat = multimaterial()
		mat.count = stdnum_mtl.value
 
		for i=1 to mat.count do
			mat[i] = standardmaterial name:(basename.text + i as String) diffusecolor:(random black white)
 
		meditmaterials[activeMeditSlot] = mat
	)--end on
)--end ro
 
rollout b "Vray Multi/Sub-Object" width:250 height:400
(	
	editText basename "Material Base Name: " pos:[25,4] width:178 height:16 text:"myMaterial"
	spinner vraynum_mtl "Vray Sub Mtl count" pos:[35,26] width:164 height:16 range:[2,100,10] type:#integer fieldwidth:40
	button btn_2 "Create" pos:[20,47] width:200 height:20
 
	on btn_2 pressed do
	(
		mat = multimaterial()
		mat.count = vraynum_mtl.value
 
		for i=1 to mat.count do
			mat[i] = Vraymtl name:(basename.text + i as String) diffuse:(random black white)
 
		meditmaterials[activeMeditSlot] = mat
	)--end on
)--end ro
 
rollout c "MentalRay Multi/Sub-Object" width:250 height:400
(
	editText basename "Material Base Name: " pos:[24,4] width:178 height:16 text:"myMaterial"
	Spinner Mraynum_mtl "MentalRay Sub Mtl count" pos:[35,26] range:[2,100,10] fieldwidth:40 type:#integer align:#left
	button btn_3 "Create" pos:[20,47] width:200 height:20 align:#left
 
	on btn_3 pressed do
	(
 
		mat = multimaterial()
		mat.count = Mraynum_mtl.value
 
		for i=1 to mat.count do
			mat[i] = Arch___Design__mi name:(basename.text + i as String) diffuse:(random black white)
 
		meditmaterials[activeMeditSlot] = mat
	)--end on
)--end ro
 
rollout d "About" width:200 height:200
(
label lbl1 "Multi/Sub-Object Presets v0.5" align:#center
label lbl2 "Created by Andy Butler" align:#center
HyperLink homepage "SB_Tools" pos:[85,40] width:65 height:15 address:"http://www.scriptspot.com/users/script-butler/" color:(color 255 255 255) hovercolor:(color 255 0 0) visitedcolor:(color 255 153 51)
label lbl3 "A big thank-you to Br0t for his scripting help" align:#center
)--end ro
 
rof=newrolloutfloater "Multi/Sub-Object Presets v0.4" 250 320 
 
addRollout a rof rolledUp:false
addRollout b rof rolledUp:false
addRollout c rof rolledUp:false
addRollout d rof rolledUp:true

Cheers.

Cheers.

Script_Butler

tassel's picture

You should also change the

You should also change the materials so they do not have the same name.

And.. MentalRay ;)

Arch___Design__mi

/ Raymond

Script_Butler's picture

Good point.

I've just changed that, and added in the mental ray presets.

Eventually i want to add a way to specify the main material name and then all the sub materials automatically name the same but incrementally. That's way abouve my scripting capability at the moment, I can't even get the spinner values to translate in to the mat.count

Have a look at my script on here to see what i want to add in, your ideas are already in hand!

I'll get there, perseverance is key! I just need a few pointers freqently!

Cheers.

Script_Butler

br0t's picture

I hope you dont mind me

I hope you dont mind me rewriting some stuff. If you have the amount of submaterials you want to create from the spinner, you can loop that often and create a submaterial each time. Diffuse color is generated randomly, and Ive added an edittextfield which text will be used as the base material name. You can add text to strings, in this case the number of the loop/material by simply saying "+".

--try killing the old dialog, if there is one
try(closeRolloutFloater rof)catch()
 
rollout a "Multi/Sub-Object Presets" width:350 height:496
(
	button btn_1 "Create" pos:[124,26] width:60 height:16
	label lbl1 "Standard" pos:[8,26] width:112 height:16
	spinner stdnum_mtl "Standard Sub Mtl count" pos:[20,47] width:164 height:16 range:[2,100,10] type:#integer fieldwidth:40
	button btn_2 "Create" pos:[124,66] width:60 height:16
	label lbl2 "Vray" pos:[8,66] width:112 height:16
	spinner vraynum_mtl "Vray Sub Mtl count" pos:[42,87] width:142 height:16 range:[2,100,10] type:#integer fieldwidth:40
	editText basename "Material Base Name: " pos:[6,4] width:178 height:16 text:"myMaterial"
 
	on btn_1 pressed do
	(
		mat = multimaterial()
		mat.count = stdnum_mtl.value
 
		for i=1 to mat.count do
			mat[i] = standardmaterial name:(basename.text + i as String) diffusecolor:(random black white)
 
		meditmaterials[activeMeditSlot] = mat
	)--end on
	on btn_2 pressed do
	(
		mat = multimaterial()
		mat.count = vraynum_mtl.value
 
		for i=1 to mat.count do
			mat[i] = Vraymtl name:(basename.text + i as String) diffuse:(random black white)
 
		meditmaterials[activeMeditSlot] = mat
	)--end on
)--end ro
 
rollout b "About" width:200 height:200
(
label lbl1 "Multi/Sub-Object Presets v0.5" pos:[55,8] width:112 height:16
label lbl2 "Created by Andy Butler" pos:[30,24] width:160 height:16
HyperLink homepage "SB_Tools" pos:[70,56] width:65 height:15 address:"http://www.scriptspot.com/users/script-butler/" color:(color 255 255 255) hovercolor:(color 255 0 0) visitedcolor:(color 255 153 51)
)--end ro
 
rof=newrolloutfloater "Multi/Sub-Object Presets v0.5" 226 256 
 
addRollout a rof rolledUp:false
addRollout b rof rolledUp:false

Cheers

Never get low & slow & out of ideas

Script_Butler's picture

No problem

Hi Br0t.

I don't mind at all that you've done that. I will give you a credit on the script in the "about" rollout.

I wanted to do exactly those things but i've only bee teaching myself maxscipt for a couple of weeks. I had an idea about getting the mat.count in using the spinner but couldn't get in in the right order/place.

The random material thing was my next step. I can now see by looking at the script ecatly how you've done it and it makes complete sense.

I'll add in the MentalRay code that i did yesterday.

I will be adding a few more features on the colour side of things. I'd like to have a few presets that people can choose from by picking colour swatches.

Thanks for your help, it's greatly appreciated.

Cheers.

Script_Butler

Script_Butler's picture

I'm still none the wiser i'm afriad!

Heres my currect script.

rollout a "Multi/Sub-Object Presets" width:350 height:496
		(
			button btn_1 "Create" pos:[124,10] width:60 height:16 align:#left
			label lbl1 "Standard" pos:[8,10] width:112 height:16
			Spinner stdnum_mtl "Standard Sub Mtl count" range:[2,100,10] fieldwidth:40 type:#integer align:#right
			button btn_2 "Create" pos:[124,50] width:60 height:16 align:#left
			label lbl2 "Vray" pos:[8,50] width:112 height:16
			Spinner vraynum_mtl "Vray Sub Mtl count" range:[2,100,10] fieldwidth:40 type:#integer align:#right
 
 
			on btn_1 pressed do
			(
				mat = multimaterial()
					mat.count = 10
					mat[1] = standardmaterial name:"Standard 1" diffusecolor:[255,0,0]
					mat[2] = standardmaterial name:"Standard 2" diffusecolor:[255,125,0]
					mat[3] = standardmaterial name:"Standard 3" diffusecolor:[255,255,0]
					mat[4] = standardmaterial name:"Standard 4" diffusecolor:[125,255,0]
					mat[5] = standardmaterial name:"Standard 5" diffusecolor:[0,255,0]
					mat[6] = standardmaterial name:"Standard 6" diffusecolor:[0,0,255]
					mat[7] = standardmaterial name:"Standard 7" diffusecolor:[0,125,255]
					mat[8] = standardmaterial name:"Standard 8" diffusecolor:[0,0,255]
					mat[9] = standardmaterial name:"Standard 9" diffusecolor:[125,0,255]
					mat[10] = standardmaterial name:"Standard 10" diffusecolor:[255,0,255]
 
					meditmaterials[activeMeditSlot] = mat
 
		)
		on btn_2 pressed do
			(
				mat = multimaterial()
						mat.count = 10
						mat[1] = Vraymtl name:"VRay 1" mat[1].Diffuse = color 255 0 0
						mat[2] = Vraymtl name:"VRay 2" mat[2].Diffuse = color 255 125 0
						mat[3] = Vraymtl name:"VRay 3" mat[3].Diffuse = color 255 255 0
						mat[4] = Vraymtl name:"VRay 4" mat[4].Diffuse = color 125 255 0
						mat[5] = Vraymtl name:"VRay 5" mat[5].Diffuse = color 0 255 0
						mat[6] = Vraymtl name:"VRay 6" mat[6].Diffuse = color 0 0 255
						mat[7] = Vraymtl name:"VRay 7" mat[7].Diffuse = color 0 125 255
						mat[8] = Vraymtl name:"VRay 8" mat[8].Diffuse = color 0 0 255
						mat[9] = Vraymtl name:"VRay 9" mat[9].Diffuse = color 125 0 255
						mat[10] = Vraymtl name:"VRay 10" mat[10].Diffuse = color 255 0 255
 
					meditmaterials[activeMeditSlot] = mat
 
		)
	)
			rollout b "About" width:200 height:200
			(
			label lbl1 "Multi/Sub-Object Presets v0.5" pos:[55,8] width:112 height:16
			label lbl2 "Created by Andy Butler" pos:[30,24] width:160 height:16
			HyperLink homepage "SB_Tools" pos:[70,56] width:65 height:15 address:"http://www.scriptspot.com/users/script-butler/" color:(color 255 255 255) hovercolor:(color 255 0 0) visitedcolor:(color 255 153 51)
			)
 
			rof=newrolloutfloater "Multi/Sub-Object Presets v0.5" 226 256 
 
		addRollout a rof rolledUp:false
		addRollout b rof rolledUp:false
)

What i want to achieve is :-

When Spinner stdnum_mtl value is put on 15, it changes the mat.count to 15 when btn_1 is pressed and the material is created with 15 sub materials.

Where would I put this event handler? I always get lost and confused as to whether things go inside our ourside of brackets.

Sorry for the simpleness, I'm still learning!

Cheers.

Script_Butler

br0t's picture

you can get a spinners value

you can get a spinners value like so:
 spn_mySpinner.value

there is also an event handler to change stuff when the spinner value is changed:

 on spn_mySpinner changed theVal do
    myVar = theVal

Cheers

Never get low & slow & out of ideas

Comment viewing options

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