i can insert this in the script in the first post?
assign default vray material
I’ve modified the function to assign “default” or “chrome” VRay material to the selection.
It accepts a parameter “type” to define which material you want (#chrome or #default).
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]
)
for o in selection do o.Material = if asCopy then copy mat else mat
)
)
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?
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)
)
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?
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.
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?
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
Vraychrome
Vraygray
Vraywhite
for the IOR ''reflection_fresnel:off ‘’ worked. thank you.
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)
)
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
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
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
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
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
I think this can be a satisfying way to get into coding
