assign default vray material


#5

i wanted to add also a white 220/220/220 material. like this?

fn AssignMat asCopy:false type:#default =
(
if selection.count > 0 do
(
case type of
(
#chrome: mat = VRayMtl Diffuse:[0,0,0] Reflection:[229,229,229]
#default: mat = VRayMtl Diffuse:[128,128,128]
#white: mat = VRayMtl Diffuse:[220,220,220]
)
for o in selection do o.Material = if asCopy then copy mat else mat
)
)

can i now add this as a shortcut to a menu or toolbar?


#6

The #white option you added is correct. Now to make a shortcut for this is not as simple, as this function has 6 options, so you would need 6 different Macros (asCopy true/false and 3 materials) or 1 Macro with a popup window where you can select the options you want.

Here is a MacroScript that will open a popup dialog. You will find it in the Customize menu under Category “Medit Tools”. The Action name is “Assign VRay Material”

macroScript AssignVRayMaterial
 category:"Medit Tools"
 tooltip:"Assign VRay Material"
 (
 	
 	rollout ro_assign_material "Assign VRay Material" width:120 height:112
 	(
 		button bt_default "Default" pos:[8,8] width:104 height:24
 		button bt_chrome "Chrome" pos:[8,32] width:104 height:24
 		button bt_white "White" pos:[8,56] width:104 height:24
 		checkbox chk_asCopy "As Copy" pos:[8,88] width:104 height:16
 		
 		local AssignMat
 
 		fn AssignMat asCopy:false type:#default =
 		(
 			if selection.count > 0 do
 			(
 				case type of
 				(
 					 #chrome: mat = VRayMtl Diffuse:[0,0,0] Reflection:[229,229,229]
 					#default: mat = VRayMtl Diffuse:[128,128,128]
 					  #white: mat = VRayMtl Diffuse:[220,220,220]
 				)
 				for o in selection do o.Material = if asCopy then copy mat else mat
 			)
 		)		
 		
 		on bt_default pressed do AssignMat asCopy:(chk_asCopy.checked) type:#default
 		on bt_chrome pressed do AssignMat asCopy:(chk_asCopy.checked) type:#chrome
 		on bt_white pressed do AssignMat asCopy:(chk_asCopy.checked) type:#white
 	)
 		
 	createdialog ro_assign_material style:#(#style_titlebar, #style_toolwindow, #style_sysmenu)
 	
 )

#7

works. thank you


#8

the created materials have the same name ‘‘VRayMtl’’. what would i need to add in to the script so that the name is ‘‘material#number’’ like with other new crreated materials?


#9

i am trying to turn off IOR fresnel reflections on the chrome material

now its
#chrome: mat = VRayMtl Diffuse:[0,0,0] Reflection:[229,229,229]

i am trying like this
#chrome: mat = VRayMtl Diffuse:[0,0,0] Reflection:[229,229,229] Reflection_ior : boolean

but fresnel reflections are not unchecked.


#10

For that you would need to keep a global variable to track the number of materials created. Otherwise there could be a field in the UI where you can enter the name you want.
What would you like to do and how would you want the names be?


#11

Try some of the following:

-- Set the Fresnel Reflection IOR value to 0.0
  reflection_ior:0.0
  
 -- Turn Fresnel Reflection ON (checked)
 reflection_fresnel:on
  
 -- Turn Fresnel Reflection OFF (unchecked)
 reflection_fresnel:off

#12

Vraychrome
Vraygray
Vraywhite

for the IOR ''reflection_fresnel:off ‘’ worked. thank you.


#13

This will add the names with a 3 digits number, ie: “Vraywhite_001”. The numbers are stored in a global variable that will last until you close max or until you “reset” the variable. To reset the counter you can type this in the Listener:

vrnames=()

You can also add a button to do it if you would like.

macroScript AssignVRayMaterial
 category:"Medit Tools"
 tooltip:"Assign VRay Material"
 (
 	 
 	 rollout ro_assign_material "Assign VRay Material" width:120 height:112
 	 (
 		 button bt_default "Default" pos:[8,8] width:104 height:24
 		 button bt_chrome "Chrome" pos:[8,32] width:104 height:24
 		 button bt_white "White" pos:[8,56] width:104 height:24
 		 checkbox chk_asCopy "As Copy" pos:[8,88] width:104 height:16
 		 
 		 local AssignMat
 		global vrnames
  
 		fn IntToString pInt = formattedPrint pInt format:"03d"
 		
 		 fn AssignMat asCopy:false type:#default =
 		 (
 			if vrnames == undefined do vrnames = #(1,1,1)
 			
 			 if selection.count > 0 do
 			 (
 				 case type of
 				 (
 					 #chrome:
 					(
 						mat = VRayMtl Diffuse:[0,0,0] Reflection:[229,229,229] name:("Vraychrome_" + IntToString vrnames[1])
 						vrnames[1] += 1
 					)
 					 #default:
 					(
 						mat = VRayMtl Diffuse:[128,128,128] name:("Vraygray_" + IntToString vrnames[2])
 						vrnames[2] += 1
 					)
 					#white:
 					(
 						mat = VRayMtl Diffuse:[220,220,220] name:("Vraywhite_" + IntToString vrnames[3])
 						vrnames[3] += 1
 					)
 				 )
 				 for o in selection do o.Material = if asCopy then copy mat else mat
 			 )
 		 )
 		 
 		 on bt_default pressed do AssignMat asCopy:(chk_asCopy.checked) type:#default
 		 on bt_chrome pressed do AssignMat asCopy:(chk_asCopy.checked) type:#chrome
 		 on bt_white pressed do AssignMat asCopy:(chk_asCopy.checked) type:#white
 	 )
 		 
 	 createdialog ro_assign_material style:#(#style_titlebar, #style_toolwindow, #style_sysmenu)
 	 
 )

#14

the names work perfectly. thank you


#15

Hi PolyTools3D, Glossiness 0.5 how can i add? thank you


#16

I don’t have the answer off the top of my head (it’ll be something like glossinessAmount) but a quick way of finding out is you turn on the macrorecorder and then make the change you need manually in material editor, you’ll see the code you need


#17

Is it possible? thank you for answering


#18

Yes, turn on the macro recorder in the maxscript listener, do the change manually in material editor, then look at the maxscript listener.

It will show you the line of code you need to change glossiness, then you can add it to the script


#19

I didn’t understand what you said because unfortunately i can’t write code, so sorry :slight_smile: :cry:


#20

No probs, but I can’t help much I’m afraid - I don’t have Vray installed on my machine at the moment. If you can find out what the maxscript listener says, I can tell you where to put it in @PolyTools3D 's code.

You just have to go to Scripting->MacroRecorder to turn the recorder on.

Then open material editor, make a vray material, change the glossiness value or whatever it is you want to change.

Then open the maxscript listener (Scripting->Maxscript Listener) and look for any code that says something about glossiness. Copy and paste that here


#21

actionMan.executeAction 0 “50048” – Tools: Material Editor Toggle
rootScene[#SME][#View1][#Material__40____VRayMtl].Properties.reference.Diffuse = color 50 50 50
rootScene[#SME][#View1][#Material__40____VRayMtl].Properties.reference.Reflection = color 200 200 200
rootScene[#SME][#View1][#Material__40____VRayMtl].Properties.reference.reflection_glossiness = 0.5
actionMan.executeAction 0 “40472”

thank you so much bro


#22

Ok, so in @PolyTools3D 's code, anywhere where it says "mat = VrayMtl " you can add reflection_glossiness:0.5 at the end - so for the chrome option, the default option or the white option. Like this:

 					 #chrome:
 					(
 						mat = VRayMtl Diffuse:[0,0,0] Reflection:[229,229,229] name:("Vraychrome_" + IntToString vrnames[1]) reflection_glossiness:0.5
 						vrnames[1] += 1
 					)
 					 #default:
 					(
 						mat = VRayMtl Diffuse:[128,128,128] name:("Vraygray_" + IntToString vrnames[2]) reflection_glossiness:0.5
 						vrnames[2] += 1  
 					)
 					#white:
 					(
 						mat = VRayMtl Diffuse:[220,220,220] name:("Vraywhite_" + IntToString vrnames[3]) reflection_glossiness:0.5
 						vrnames[3] += 1  
 					)

Give that a go and play around with it a bit :slight_smile: I think this can be a satisfying way to get into coding


#23

Thanks u so much, worked. :heart_eyes:
but, “rollout” opened popup menu and 3 materials available. i need u without popup just one material, only shortcut and assign one default material. i m editing try, i hope it work :grin:
Thanks for your time bro.


#24

You’re welcome. Maybe it’s faster for you to start with the code posted at the start of this thread:

(
 	-- Create a test object
 	obj = Sphere()
 	
 	-- Create a new VRay material
 	mat = VRayMtl()
 	
 	-- Change the Diffuse color to Black
 	mat.Diffuse = [0,0,0]
 	
 	-- Change the Reflection value to 90%
 	mat.Reflection = [255,255,255] * 0.9
 
 	-- Assign the VRay material to the Object
 	obj.Material = mat
 )

Of course you need to add your

mat.reflection_glossiness = 0.5

And instead of making a sphere and applying the material at the end of the code, you could just stick the material in the first material editor slot with

meditmaterials[1] = mat

so you can use it however you want.

or another example, you could assign it directly to a selected object with

$.mat = mat