MaxScript DirectX_Shader Issues

I’m having an issue in MaxScript whereby the first time I try to modify for get the value of a property in a DirectX_Shader material using MaxScript, it will kick back an error to the effect of “Unknown property—”

So if I had something like this:

currentMaterial = 
dxProps = getPropNames currentMaterial.DirectX_Shader
for dxProp in dxProps do
(
     evalString = "currentMaterial.DirectX_Shader." + dxProp
     execute(evalString)
)

The first time I evaluate the code, “execute(evalString)” would raise an exception. Every subsequent time I evaluate the code, no exception is raised until I reboot 3DS Max.

Has anyone else encountered this before and know a workaround or solution?

I’d also like to know if anyone knows of a better way of looping over all properties in a DirectX_Shader in this fashion without using the execute command.

  • i guess “currentMaterial = …” is missing some parts ? otherwise the code would’nt make sense

  • there is no property “DirectX_shader” in the (3dsMax) DirectX material - so GetPropNames will fail at least if it’s a standard 3ds Max dx material

  • call “execute” without using clauses arround the argument, maxscript functioncalls do not use clauses around the arguments, except when no arguments are passed, like somecall()

execute evalString

the syntax for function calls In Maxscript only uses (empty) clauses when the call does not take arguments…

You shouldn’t be appending “.DirectX_Shader”


currentMaterial = somePreviouslyDefinedMat
//dxProps = getPropNames currentMaterial.DirectX_Shader
//should be:
dxProps = getPropNames currentMaterial

for dxProp in dxProps do
(
     //evalString = "currentMaterial.DirectX_Shader." + dxProp
     //should be
     evalString = "currentMaterial." + dxProp

     execute evalString
)


local DirectxShaderProperties = getpropnames ($.material.delegate)


getproperty $.material.delegate #effectFile

Ah right, forgot about getproperty.

.delegate won’t work if it’s a standard DX shader, though (ie, not a scripted material plugin).

henceforth, if you have a standard DX shader:


dxProps = getPropNames currentMaterial
for dxProp in dxProps do (
  getproperty currentMaterial dxProp
)

Then just stick a “.delegate” to the end of currentMaterial if you’re using a scripted material plugin.

The trick of it is that it’s a scripted material plugin we’re using in-house. The DirectX_Shader is a property of the the material with its own set of properties.

LoTekk and Nysuatro win for using “GetProperty”. Using “SetProperty” also cleared up other issues which I’ll wager all stemmed from the same source.

Thanks for your help, gents!