Script for mats

Anyone know of or have a script to change shader types? I need to find all ward shaders in a scene and switch them to blinn or phong. The infamous “red dot” problem.

Try the MaterialControl maxscript from the blur scripts collection.

http://www.neilblevins.com/blurscripts/blurscripts.htm

does not seem to work on VRay materials

Run zis and select all the objects you want changed:


Rollout changeBRDF "Change BRDF"
(	
	global brdf = 0

	radiobuttons brdf_type labels:#("Phong", "Blinn", "Ward")
	button applyIt "Apply" width:200 align:#right

	on brdf_type changed state do
	(
		global brdf = brdf_type.state as integer - 1
	)

	on applyIt pressed do
	(
		ObjArray = selection as array

		for m in 1 to ObjArray.count do
		(
			if (classof ObjArray[m].material == VRayMtl) then
			(
				ObjArray[m].material.brdf_type = brdf
			)

		)
	)
)

createdialog changeBRDF width:300

Thanks! getting error though

-- Type error: CreateDialog requires RolloutClass, got: undefined

Piss. You on max 9?

Yar

Try this then - select everything and evaluate the code:


      ObjArray = selection as array

      for m in 1 to ObjArray.count do
      (
         if (classof ObjArray[m].material == VRayMtl) then
         (
            ObjArray[m].material.brdf_type = 1
         )

      )
   ) 

And for phong:


      ObjArray = selection as array

      for m in 1 to ObjArray.count do
      (
         if (classof ObjArray[m].material == VRayMtl) then
         (
            ObjArray[m].material.brdf_type = 0
         )

      )
   ) 

this should do the trick…“refs.dependson” is a killer for recursive stuff!

clearlistener()

fn removeward mat =
(
local mats = #()
local scenemats = refs.dependsOn mat
for r in scenemats do    
(
	if (classof r == vraymtl) then
            append mats r

        join mats (removeward r)
    )
	return mats
)

for t in scenematerials do 

mymats = removeward scenematerials
for i in mymats do
(
print i
if i.brdf_type == 2 then (i.brdf_type = 1) else()
)

this script goes everywhere, no matter if your vraymaterial is inside a multimat,blend, whatever and how deep nested.

regards,michael


(
Rollout changeBRDF "Change BRDF"
(   
   global brdf = 0

   radiobuttons brdf_type labels:#("Phong", "Blinn", "Ward")
   button applyIt "Apply" width:200 align:#right

   on brdf_type changed state do
   (
      global brdf = brdf_type.state as integer - 1
   )

   on applyIt pressed do
   (
      ObjArray = selection as array

      for m in 1 to ObjArray.count do
      (
         if (classof ObjArray[m].material == VRayMtl) then
         (
            ObjArray[m].material.brdf_type = brdf
         )

      )
   )
)

createdialog changeBRDF width:300
)

try this to fix the error with the rolloutcreator
(additional wrapping parenthesis)

I’m still using max 8 over here (no reason to install 9 yet) so sorry I couldnt check :confused:

get the following error, for all of the above so Im not sure
if I am executing it incorrectly or error in the script
-- Syntax error: at ), expected <factor>
-- In line: )

oops, looks like i pasted the wrong code…

try this again:

clearlistener()

fn removeward mat =
(
local mats = #()
local scenemats = refs.dependsOn mat
for r in scenemats do   
(
   if (classof r == vraymtl) then
            append mats r

        join mats (removeward r)
    )
   return mats
)

mymats = removeward scenematerials
for i in mymats do
(
print i
if i.brdf_type == 2 then (i.brdf_type = 1) else()
)

Sorry guys lost my PSU! Ok this works. Thanks so much.