VRay MaxScript question ...

Hi guys,

I’m trying to write a script to automatically set certain VRay material values of all VRay mats in the scene, by entering one value in the script. But how do I avoid the script trying to set specific VRay material settings in native Max materials in the scene, causing an unknown property error?

Here’s my script so far:

------------------------------------------------

MainFloater = NewRolloutFloater “Set VRay properties” 300 315

Rollout VRaymat_prop_refl_subd “VRay mat refl subdivs”
(

group “Refl subdivs value”
    (

label enterreflsubdvalue “Enter refl subdivs value for all VRay mats in the scene”
    spinner reflsubdvalue align:#center range:[1,1000,15] type:#integer scale:1 fieldwidth:45
    button setreflsubdvalue “Set refl subdivs”

) -- close group

on setreflsubdvalue pressed do
        (
        for i = 1 to sceneMaterials.count do
            (
            sceneMaterials*.reflection_subdivs = reflsubdvalue.value*
            )
        )

) -- close rollout

AddRollout VRaymat_prop_refl_subd MainFloater

------------------------------------------------

Thanks very much in advance for your help.

Cheers,

Metin

Got it figured out. The important part of the script now reads:

on setreflsubdvalue pressed do
        (
        for m in sceneMaterials do
            (
            if classof m == VRayMtl then
                (
                m.reflection_subdivs = reflsubdvalue.value
                )
            )
        )

well, brute and slow method:

try sceneMaterials.reflection_subdivs = reflsubdvalue.value
catch()

better:

if sceneMaterials.reflection_subdivs != undefined then sceneMaterials.reflection_subdivs = reflsubdvalue.value

in case this doesn’t work:

if ((classOf sceneMaterials) == VrayMaterial) then sceneMaterials*.reflection_subdivs = reflsubdvalue.value*

something like that…i’m not sure if the classOf is really VrayMaterial, you have to try it out.

Thanks Plastic,

My method seems to work, so being a script sucker I guess I’ll leave it that way. :slight_smile:

Cheers,

Metin

yeah it’s the fastest way anyway…you just don’t really need all the brackets :wink:

:sweat_smile: :smile: But it looks like I’m a real programmer that way. :wink:

By the way, the first version of my script “The VRay automator” is finished. :slight_smile: You can find it here:

http://www.metinseven.com/menu\_goodies.htm

Spread the word and lemme know if you’ve got cool suggestions for the script.

Cheers,

Metin