[Closed] assign default vray material
i am looking for a script where i can quickly assign a material to a selected object . i would make a shortcut for the script
- default vray material with 50% grey diffuse
- chrome vray material with black diffuse and 90% reflections.
what would be the basic for assigning a material?
http://www.scriptspot.com/forums/3ds-max/general-scripting/create-and-assign-material-mr-why-its-duplicating
fn assignMat asCopy:off = ( if selection.count > 0 do ( material = Arch___Design__mi name:“TestMat” diff_weight:.02 refl_weight:1 refr_weight:.9 \ refl_func_fresnel:on opts_1sided:on opts_propagate_alpha:on opts_refl_depth:10 opts_refr_depth:10 – “asCopy” argument in the function mean that you have choise to assigne material as instance or copy for o in selection do o.mat = if asCopy then (copy material) else material ) )
Default vray material with 50% grey diffuse
(
-- Create a test object
obj = Sphere()
-- Create a new VRay material
mat = VRayMtl()
-- Change the Diffuse color to Gray (50%)
mat.Diffuse = [128,128,128]
-- Assign the VRay material to the Object
obj.Material = mat
)
Chrome vray material with black diffuse and 90% reflections
(
-- 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
)
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?
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?
Vraychrome
Vraygray
Vraywhite
for the IOR ”reflection_fresnel:off ‘’ worked. thank you.
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.
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
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)
)