Notifications
Clear all

[Closed] MaxScript MATTE Global Override

Hello everyone
I’m relatively new to Max scripting so I have few problems to solve which I didn’t found on help or other forums.

I want my script to, when selecting geometry, filter only geometry when selecting by name (multiple objects – only Geometry – no helpers, cameras, shapes or so), the same thing with cameras. Also, to check those, I want them to print in the text box under the buttons and connect selected camera to render button.
Then, when my objects are selected and printed, on “Update” button, next to render button, I want to apply a Global MATTE material override to selected geometry (mental ray) on chosen radio button “Front” – when “Front” is chosen – it should apply MATTE to previously selected geometry MESH objects and when Back is selected to do vice versa, to apply on objects that are not selected and printed in the box – I don’t know how to do that so I’m asking someone to help and I would really appreciate it.

The script code is below. Thanks in advance.

Rollout TestMatte "Test MATTE" width: 220
(
	button folder_button "..." tooltip:"Pick path for render" align:#left width:30 offset: [0,0] across:2 height:18
	edittext file_path "" readonly:true align:#right height:18 width:165
	
	button bnSelGeom "Select Geometry" tooltip:"" align:#right height:30 width:97 across:2
	button bnSelCamera "Select Camera" tooltip:"" align:#left height:30 width:97
	edittext nameMesh "" readonly:true align:#left height:50 width:97 across:2			
	edittext nameCamera "" readonly:true align:#right height:50 width:97
	
	label rend_option "Render:" align:#left across:2
	radiobuttons rad_pozeks "" labels:#("Front","Back") default:0 align:#left offsets:#([-50,0],[-40,0])

	button bnUpdate "Update" align:#left across:2 width: 97 height:30
	button bnRender "Render" align:#right width:97 height:30
	
	


	
	on bnSelGeom pressed do
			(
				fn selmesh obj = 
				(
					return superclassof obj == geometryClass
				)
				chosenMesh = selectByName title:"Pick" \ 
				buttontext:"Pick" filter:selmesh showHidden:true
				--nameMesh.text = chosenMesh.name       <<<this should be multiple mesh objects printed on editbox under select Geometry button
			)
		
		
		on bnSelCamera pressed do
		(
			fn selCamera obj = 
			(
				return superclassof obj == camera
			)
			global chosenCamera = selectByName title:"Pick" \ 
			buttontext:"Odaberi" count:#multiple filter:selCamera showHidden:true
			--nameCamera.text = chosenCamera.name       <<<this should be camera name printed on editbox under select camera button
		)
			
			
		on folder_button pressed do
			(
				global folderPath = getSavePath() + "\\"
				file_path.text = folderPath
			)
	
local frontCamera = chosenCamera   --<<<this should be selected camera for render
local locationFolder = folderPath as string
			

	fn callRenderFront theID = 
			(
				newName1 = locationFolder + "test1" + ".png"
				global render1 = render camera:frontCamera vfb:false \
				outputwidth:256 outputheight: 256 
				render1.filename = newName1
				save render1
			)

	
		fn callRenderBack theID =
			(				
				newName2 = locationFolder + "test1" + "-" + "test2" + ".png"
				global render2 = render camera:frontCamera vfb:false \
				outputwidth:256 outputheight: 256
				render2.filename = newName2
				save render2
			)
				
	
		on bnRender pressed do 
			(
				renderRadio = case rad_pozeks.state of
					(
						1: (callRenderFront "Render")
						2: (callRenderBack "Render")
					)
			)
			
	
	)
createdialog TestMatte
3 Replies

Do you have any suggestion how we can test your script?

May I give you some advice? Prepare scene for test. Describe all steps how to reproduce an issue. Tell us about expected result.

If you do this, your changes to get a response will be much higher.

Probably not exactly what you want, as the description is a little confusing, but hopefully you can get some useful thing out of it.

try destroydialog ::TestMatte catch()

Rollout TestMatte "Test MATTE" width: 220
(
	button       bt_selectFolder   "..." tooltip:"Pick path for render" align:#left width:30 offset: [0,0] across:2 height:18
	edittext     tx_folder         "" readonly:true align:#right height:18 width:165
	
	button       bt_SelectGeometry "Select Geometry" align:#right height:30 width:97 across:2
	button       bt_SelectCamera   "Select Camera"   align:#left  height:30 width:97
	listbox      list_geometry     "" align:#left  height:10 width:97 across:2 readOnly:true enabled:false
	listbox      list_cameras      "" align:#right height:10 width:97
	
	label        rend_option       "Render:" align:#left across:2
	radiobuttons rad_options       "" labels:#("Front","Back") align:#left offsets:#([-50,0],[-40,0])

	button       bt_update         "Update" align:#left across:2 width: 97 height:30
	button       bt_render         "Render" align:#right width:97 height:30
	
	local matteMaterial
	local theObjects = #()
	local theCameras = #()
	local outputFolder = undefined
	
	on TestMatte open do
	(
		/* Create your own matte material */
		matteMaterial = standard diffuse:green selfIllumAmount:100
	)
	
	fn FilterGeometry obj = isKindOf obj geometryClass and not isKindOf obj Targetobject
	
	fn FilterCameras  obj = isKindOf obj camera
	
	on bt_SelectGeometry pressed do
	(
		sel = selectByName title:"Pick" filter:FilterGeometry showHidden:true
		if sel != undefined then
		(
			theObjects = sel
			list_geometry.items = for j in theObjects collect j.name
		)else(
			list_geometry.items = #()
			theObjects = #()
		)
	)

	on bt_SelectCamera pressed do
	(
		sel = selectByName title:"Pick" filter:FilterCameras showHidden:true
		if sel != undefined then
		(
			theCameras = sel
			list_cameras.items = for j in theCameras collect j.name
		)else(
			list_cameras.items = #()
			theCameras = #()
		)
	)

	on bt_selectFolder pressed do
	(
		outputFolder = getSavePath()
		if outputFolder != undefined then tx_folder.text = outputFolder else tx_folder.text = ""
	)
	
	on bt_render pressed do 
	(
		if outputFolder == undefined do return messagebox "No Output Folder Selected"
		if theObjects.count == 0 do return messagebox "No Geometry Selected"
		if theCameras.count == 0 do return messagebox "No Camera Selected"
		
		setwaitcursor()
		
		/* Get the Camera from the ListBox Selection */
		cam = theCameras[list_cameras.selection]
		
		case rad_options.state of
		(
			1:
			(
				matteObjects = theObjects
				filename = outputFolder + "\\" + cam.name + "_FrontRender.png"
			)
			2:
			(
				matteObjects = for j in geometry where finditem theObjects j == 0 collect j
				filename = outputFolder + "\\" + cam.name + "_BackRender.png"
			)
		)
		
		/* Save the Objects Material */
		oldMaterials = for j in matteObjects collect #(j, j.material)
		
		/* Repalce the materials with the Matte material */
		matteObjects.material = matteMaterial
		
		/* Render the Images */
		render camera:cam vfb:false outputwidth:256 outputheight:256 outputfile:filename
		
		/* Restore the Materials */
		for j in oldMaterials do j[1].material = j[2]
		
		messagebox ("Image Rendered to:
" + filename)
		
		setarrowcursor()
	)
)

createdialog TestMatte

Jorge Rodríguez – Thank you, thank you and thank you! That was exactly what I wanted! All I need is to change standard green material in this case to MentalRay (Matte/shadow/reflection) with unchecked recieve shadows, use AO and receive reflections but I’ll figure it out Thank you for your time and help, I really appreciate it.