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)
)