Notifications
Clear all

[Closed] Radiobuttons

Hello again. I have had help here before which I am very grateful for. I am now stuck on something which I’m guessing should be quite simple.

This is the tool I’ve been working on, it applies uvmaps of a certain size to individual faces. It basically works how I want it to save maybe a few bells and whistles.

(
	try(destroyDialog newscript1)catch()
-----------------------------------------------------------------------------------------------------
	rollout newscript1 "Texture Tools" width:232 height:436
	(
		GroupBox grp_map "Map Selection to Scale" pos:[8,8] width:216 height:128 enabled:true
		dropdownList ddl_width "" pos:[56,32] width:50 height:21 enabled:true items:#("256", "8", "16", "32", "64", "128", "256", "512", "1024", "2048") selection:1
		label lbl_ddl_width "Width" pos:[16,36] width:28 height:13 enabled:true
		dropdownList ddl_height "" pos:[56,64] width:50 height:21 enabled:true items:#("2048", "8", "16", "32", "64", "128", "256", "512", "1024", "2048") selection:1
		label lbl_ddl_height "Height" pos:[16,68] width:31 height:16 enabled:true
		spinner spn_mapCh "Map Channel	" pos:[120,36] width:96 height:16 enabled:true range:[1,5,2] type:#integer fieldwidth:18
		button btn_map "Map" pos:[112,64] width:104 height:20 enabled:true
		
		radioButtons mapOption labels:#("Individually", "Cluster") align:#left default:1 columns:1

		GroupBox grp_unwrap "Unwrap" pos:[8,144] width:216 height:88 --enabled:false
		button btn_unwrap "Unwrap" pos:[16,168] width:88 height:20
		button btn_delete "Delete" pos:[16,200] width:88 height:20
		button btn_collapse "Collapse Stack" pos:[112,200] width:104 height:20
		spinner spn_unwCh "Map Channel	" pos:[120,172] width:96 height:16 range:[1,5,2] type:#integer scale:1 fieldwidth:18	
	----------------------------------------------------------------------------
		fn alignUVGizmo theObj theFace =
		(
		 faceNormal = in coordsys theObj (polyop.getFaceNormal theObj theFace) 
		 worldUpVector = [0,0,1] 
		 rightVector = normalize (cross worldUpVector faceNormal) 
		 upVector = normalize ( cross rightVector faceNormal )
		 theMatrix = matrix3 rightVector upVector faceNormal [0,0,0]

		 theMap = Uvwmap()
		 modPanel.addModToSelection theMap ui:off
		 theMap.gizmo.transform = theMatrix
		 theMap.length = ddl_height.selected as float *0.1
		 theMap.width = ddl_width.selected as float *0.1
		 theMap.mapchannel = spn_mapCh.value
		 collapseStack $
		 subobjectLevel = 4
		)
---------------------------------------------------------------	
		on btn_map pressed do

			(
					selection_bitarray = #{}	
					b = bit.Set 0 1 true
					$.getFacesByFlag & selection_bitarray b
					
					selection_array = (selection_bitarray as array)
					num_faces = selection_array.count
					
					for i = 1 to num_faces do
					undo off
			
							(
								polyop.setFaceSelection $ (selection_array [i])
								alignUVGizmo $ (selection_array [i])
							)	
			)
---------------------------------------------------------------
		on btn_unwrap pressed do
		(
		if isKindOf $ editable_poly then
			(
				
		
					(
					modPanel.addModToSelection (Unwrap_UVW ()) ui:on
					$.modifiers[#unwrap_uvw].unwrap.edit ()
					$.modifiers[#unwrap_uvw].unwrap.move ()	
					$.modifiers[#unwrap_uvw].unwrap.setMapChannel spn_unwCh.value
					)
			)
					else
					(
					subobjectLevel = 0
					convertToPoly $
					modPanel.addModToSelection (Unwrap_UVW ()) ui:on
					$.modifiers[#unwrap_uvw].unwrap.edit ()
					$.modifiers[#unwrap_uvw].unwrap.move ()	
					$.modifiers[#unwrap_uvw].unwrap.setMapChannel spn_unwCh.value
					)
		)
		on btn_delete pressed do
			deleteModifier $ 1
		on btn_collapse pressed do
			collapseStack $
	)	
---------------------------------------------------------------	
)
createDialog newscript1 width:230 height:240

This alternative part works on it’s own without the function used in the main part of my script. It maps a selection of faces sharing the same plane.


	on btn_map pressed do

 		(
		faceArr = (polyop.getFaceSelection $) as array
		faceNormal = in coordsys $ (polyop.getFaceNormal $ faceArr[1])
		worldUpVector = [0,0,1]
		rightVector = normalize (cross worldUpVector faceNormal)
		upVector = normalize ( cross rightVector faceNormal)
		theMatrix = matrix3 rightVector upVector faceNormal [0,0,0]
		
		theMap = Uvwmap()
		modPanel.addModToSelection theMap ui:off
		theMap.gizmo.transform = theMatrix
		theMap.length = ddl_height.selected as float *0.1
		theMap.width = ddl_width.selected as float *0.1
		theMap.mapchannel = spn_mapCh.value
		collapseStack $
		subobjectLevel = 4
		)

All I want to do is to be able to use the radio button to select between the two different techniques when I press the “map” button. If someone could give me a boot in the right direction then I will be eternally grateful. I am using max9.

6 Replies
case mapoptions.state of
  (
  1: (
  --do this
  )
  2: ( 
  --do this instead
  )
  
  )

for example…

rollout rl_Test ""
 (
 	radiobuttons rdo_1 "test" labels:#("1","2","3")
 	button btn_test "test"
 	on btn_test pressed do
 	(
 		case rdo_1.state of
 		(
 			1: (
 				print "this"
 			)
 			2: (
 				print "that"
 			)
 		)
 	)
 	
 )
 CreateDialog rl_test

That simple? Thankyou sir, you’ve certainly given me the boot I asked for.

By jove that got it! Thankyou very much!

In case it is useful for anyone else…

(
	try(destroyDialog newscript1)catch()
-----------------------------------------------------------------------------------------------------
	rollout newscript1 "Texture Tools" width:232 height:436
	(
		GroupBox grp_map "Map Selection to Scale" pos:[8,8] width:216 height:118 enabled:true
		dropdownList ddl_width "" pos:[56,32] width:50 height:21 enabled:true items:#("256", "8", "16", "32", "64", "128", "256", "512", "1024", "2048") selection:1
		label lbl_ddl_width "Width" pos:[16,36] width:28 height:13 enabled:true
		dropdownList ddl_height "" pos:[56,64] width:50 height:21 enabled:true items:#("2048", "8", "16", "32", "64", "128", "256", "512", "1024", "2048") selection:1
		label lbl_ddl_height "Height" pos:[16,68] width:31 height:16 enabled:true
		spinner spn_mapCh "Map Channel	" pos:[120,36] width:96 height:16 enabled:true range:[1,5,2] type:#integer fieldwidth:18
		radioButtons mapOption labels:#("Individually", "Cluster") pos:[112,60] align:#left default:1 columns:1
		button btn_map "Map" pos:[16,94] width:200 height:20 enabled:true

		GroupBox grp_unwrap "Unwrap" pos:[8,134] width:216 height:88 --enabled:false
		button btn_unwrap "Unwrap" pos:[16,158] width:88 height:20
		button btn_delete "Delete" pos:[16,190] width:88 height:20
		button btn_collapse "Collapse Stack" pos:[112,190] width:104 height:20
		spinner spn_unwCh "Map Channel	" pos:[120,162] width:96 height:16 range:[1,5,2] type:#integer scale:1 fieldwidth:18	
	----------------------------------------------------------------------------
		fn alignUVGizmo theObj theFace =
		(
		 faceNormal = in coordsys theObj (polyop.getFaceNormal theObj theFace) 
		 worldUpVector = [0,0,1] 
		 rightVector = normalize (cross worldUpVector faceNormal) 
		 upVector = normalize ( cross rightVector faceNormal )
		 theMatrix = matrix3 rightVector upVector faceNormal [0,0,0]

		 theMap = Uvwmap()
		 modPanel.addModToSelection theMap ui:off
		 theMap.gizmo.transform = theMatrix
		 theMap.length = ddl_height.selected as float *0.1
		 theMap.width = ddl_width.selected as float *0.1
		 theMap.mapchannel = spn_mapCh.value
		 collapseStack $
		 subobjectLevel = 4
		)
---------------------------------------------------------------	
		on btn_map pressed do
		(	
			case mapoption.state of	
			(
			1:	(
						selection_bitarray = #{}	
						b = bit.Set 0 1 true
						$.getFacesByFlag & selection_bitarray b
						
						selection_array = (selection_bitarray as array)
						num_faces = selection_array.count
						
						for i = 1 to num_faces do
						undo off
				
								(
									polyop.setFaceSelection $ (selection_array [i])
									alignUVGizmo $ (selection_array [i])
								)	
				)
			2:	(
						faceArr = (polyop.getFaceSelection $) as array
						faceNormal = in coordsys $ (polyop.getFaceNormal $ faceArr[1])
						worldUpVector = [0,0,1]
						rightVector = normalize (cross worldUpVector faceNormal)
						upVector = normalize ( cross rightVector faceNormal)
						theMatrix = matrix3 rightVector upVector faceNormal [0,0,0]
						
						theMap = Uvwmap()
						modPanel.addModToSelection theMap ui:off
						theMap.gizmo.transform = theMatrix
						theMap.length = ddl_height.selected as float *0.1
						theMap.width = ddl_width.selected as float *0.1
						theMap.mapchannel = spn_mapCh.value
						collapseStack $
						subobjectLevel = 4
				)
			)
		)
---------------------------------------------------------------
		on btn_unwrap pressed do
		(
		if isKindOf $ editable_poly then
			(
				
		
					(
					modPanel.addModToSelection (Unwrap_UVW ()) ui:on
					$.modifiers[#unwrap_uvw].unwrap.edit ()
					$.modifiers[#unwrap_uvw].unwrap.move ()	
					$.modifiers[#unwrap_uvw].unwrap.setMapChannel spn_unwCh.value
					)
			)
					else
					(
					subobjectLevel = 0
					convertToPoly $
					modPanel.addModToSelection (Unwrap_UVW ()) ui:on
					$.modifiers[#unwrap_uvw].unwrap.edit ()
					$.modifiers[#unwrap_uvw].unwrap.move ()	
					$.modifiers[#unwrap_uvw].unwrap.setMapChannel spn_unwCh.value
					)
		)
		on btn_delete pressed do
			deleteModifier $ 1
		on btn_collapse pressed do
			collapseStack $
	)	
---------------------------------------------------------------	
)
createDialog newscript1 width:230 height:230
1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

The tool that you wrote can be much faster and cleaner. You don’t need uvwmap modifier at all. Simply use polyop.applyUVWMap which does do exactly the same.

I’ve tried using that before but can’t get it to do anything. I’d like to be wrong and come up with a more efficient script but I thought you had to use a modifier so you could align the gizmo to the face. It seemed to be a caveat of doing this in max9.