Scripting: Changing the default value of a shader color channel

This snippet changes the default value of a single color channel (R in this case) an existing shaderdef:

from siutils import si        # Application
from siutils import log        # LogMessage
from siutils import disp    # win32com.client.Dispatch
from siutils import C        # win32com.client.constants

def dispFix( badDispatch ):
    import win32com.client.dynamic
    # Re-Wraps a bad dispatch into a working one:
    return win32com.client.dynamic.Dispatch(badDispatch)

# Get ShaderDef for the Environment shader
sProgID = "Softimage.mia_material_phen.1.0"
oDef = si.GetShaderDef( sProgID )

# Get ShaderParamDef for the Tranformation parameter
oReflectivity = oDef.InputParamDefs.GetParamDefByName( "reflectivity" )

# Change the default value
oReflectivity.DefaultValue = 0.333

oRefl_Color = oDef.InputParamDefs.GetParamDefByName( "refl_color" )
print si.ClassName( oRefl_Color )

x = dispFix(oRefl_Color).SubParamDefs
oRed = x.GetParamDefByName( "red" )
print oRed.DefaultValue
oRed.DefaultValue = 0.325

If you are adding a new shaderdef, you can do it like this:

shaderParamDefOptions.SetDefaultValue( [0.5, 0.3, 0.2] )

hat tip: Vladimir and Vincent on the Softimage mailing list

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s