Script request- Vray material options rollout/ glossy rays

Hey guys,

first of all thanks for the great content on this site and thanks to the people contributing. I am new here, and have zero scripting experience... but would it be ok to ask for a (hopefully simple) script?

When dealing with reflective/glossy materials or when I use the Vray lens effect, I get weird artefacts on my renders (I use 3dsMax 2017 and Vray 3.4). The only solution that solved this issue completely was to change for each vray material the option 'treat glossy rays as GI rays' to 'Always', in the 'options' rollout of Vray materials (the default is always set to 'only for GI rays'). In a scene with many materials, this can become quite a time-consuming job.

This is why I would like to ask for a script that can do this automatically (for all Vray materials in the scene, to automatically change the 'treat glossy rays as GI rays' option from 'only for GI rays' to 'Always'). Since I have no programming/scripting knowledge, I have no idea if that is even possible; but I thought to give it a try. Any help would be much appreciated :)

Thanks!

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
sable806's picture

Real Code Working

This should work

for i in scenematerials do
(
	if (classOf i) == VRayMtl then
	(
		i.option_traceDiffuseAndGlossy = 2
	)
	else if (classOf i) == VrayBlendMtl then
	(
		i.baseMtl.option_tracediffuseandglossy = 2
		if i.coatMtl != 0 then
		(
			for u in i.coatMtl do
			(
				if (classOf u) == VRayMtl then
				(
					u.option_traceDiffuseAndGlossy = 2
				)
			)
		)
	)
	else if (classOf i) == Multimaterial then
	(
		For u in i.materialList do
		(
			if (classOf u) == VRayMtl then
			(
				u.option_traceDiffuseAndGlossy = 2
			)
			else if (classOf u) == VrayBlendMtl then
			(
				u.baseMtl.option_tracediffuseandglossy = 2
				if u.coatMtl != 0 then
				(
					for j in u.coatMtl do
					(
						if (classOf j) == VRayMtl then
						(
							j.option_traceDiffuseAndGlossy = 2
						)
					)
				)
			)
		)
	)
)
hory 2005's picture

Amazing job

Amazing job mate, thank you :) I def owe you a beer. Haven't tested it for the VrayBlend, but it works like a charm for multimaterials and vray materials. Thanks sooo much!!!

hory 2005's picture

Thank you

Thank you sooo much mate, it works like a charm. For each Vray material that is applied to an object in the scene, the 'treat glossy rays as GI rays' option is now automatically set to 'Always' after running the script- exactly what I wanted. You really helped me out a lot with this, I am truly grateful :)

sable806's picture

New Version

I'm glad it did !

If you have heavy scene and script is low when executing you can use the code in the other comments. Thanks to vusta the operatiosn are conducted on scene materials directly instead of browsing trough objects.

Don't hesitate to contact me if you need something else.

hory 2005's picture

More testing

Hey mate, thanks again for the great work; it helped me a lot. About the second version of the script, I can't get it to work :( Here's the error:

Error occurred in anonymous codeblock; filename: C:\Users\Hory\Desktop\New Archi\Setari Vray\alternative_glossyraysmodifier.ms; position: 64; line: 4
-- Type error: Material library index must be number or name, got: Default:Standard
-- MAXScript callstack:
-- thread data: threadID:4012
-- ------------------------------------------------------
-- [stack level: 0]
-- In i loop; filename: C:\Users\Hory\Desktop\New Archi\Setari Vray\alternative_glossyraysmodifier.ms; position: 65; line: 4
-- Parameters:
-- i: Default:Standard
-- Locals:
-- i: Default:Standard
-- Externals:
-- sceneMaterials: SystemGlobal:sceneMaterials : #materialLibrary()
-- owner: undefined
-- ------------------------------------------------------
-- [stack level: 1]
-- called from top-level

The first version you posted in this thread is great; eased my work quite a bit. However, I noticed that it does have some issues regarding multi/sub object materials (or blend material, I just noticed): for some materials in the stack, the 'treat glossy rays as GI rays' parameter gets set to 'Always' (as intended); whereas for others it just stays at the default settings ('only for GI rays'). Any ideea if it would be possible to fix this as well?

Many thanks again, mate!

sable806's picture

2nd version

I haven't tested the second version but i might know where it stucks.

For the blendMtl it is normal that no changes appears because the actual script is not looking inside blendMtl. But we could do something about it for sure !

I do not have access to any computer with 3ds max but I'll reach you on Monday.

For now this code should Work and you should look into the maxscript documentation in order to treat blendMtl.

for i in scenematerials do
(
if (classOf i) == VRayMtl then
(
i.option_traceDiffuseAndGlossy = 2
)
Else if (classOf i) == VrayBlendMtl then
(
i.mat1.option_tracediffuseandglossy = 2
i.mat2....
)
Else If (classOf i) == Multimaterial then
(
For u in i.materialList do
(
-- test If vray mtl or vray blendMtl again--
) 
) 
)

i'm actually writing it on m'y phone so There Will probably be some typing issues and i didn't tested it

hory 2005's picture

testing

Thank you again for doing this, mate!

I tested this script; unfortunately it gives the following error:

Error occurred in anonymous codeblock; filename: ; position: 199; line: 10
-- Syntax error: at .., expected
-- In line: i.mat2...

Any help would be much appreciated :)

sable806's picture

Vray material options rollout/ glossy rays

Hello, Here is a piece of code that should do what you need. Feel free to test it and make me some feedback about it.

for i = 1 to objects.count do
 
(
 
if (classOf objects[i].material) == VRayMtl then
 
(
 
objects[i].material.option_traceDiffuseAndGlossy = 2
 
)
 
) 
AttachmentSize
glossyraysmodifier.ms 151 bytes
vusta's picture

question...

in non programmer speak...

why are we counting objects when we should be counting vray materials ? so say we have 1 million objects, all assigned with the same vray material...why should we then do the same thing 1 million times ?

sable806's picture

Redundancy Check

When you use either Slate Material Editor or compact One, scene materials might not be loaded so i usually go with scene objects and get their materials. In your example if i know i have 1 million objects and one vrayMtl, i'll probably won't need a script and i'll go change the material myself. BUT, you are right i don't want to do the same operations on materials that have already been trated. So i could go for something like :

  • Creating an array which stocks the treated materials name
  • When getting an objects material, checking if it has already been processed by comparing object's material's name with names in the array
  • If Comparizon brings a match then do nothing
  • If Comparizon brings nothing then process GlossyRays as Always

Is that of any help ?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.