Notifications
Clear all

[Closed] Function with two arguments returns undefined

I have a function like that

fn assign object property = (
	object.material.property = color 150 150 150
)

Whenever I call it with something like

assign $box001 DiffuseColor

i get property:undefined.
I’ve also tried

assign $box001 "DiffuseColor"

but I cannot manage to pass that parameter to the function.

Why?

4 Replies

probably because DiffuseColor in your case is undefined.
also material doesn’t have #property property if it’s not a custom.

the function could be:

fn setNodeMaterialProperty node prop value = 
(
    if isvalidnode node and iskindof node.mat Material and isproperty node.mat prop do
    (
        setproperty node.mat prop value
    )
) 

if you absolutely sure that all parameters are valid and you have a default value to set:


fn setNodeMaterialProperty node prop value:red = 
(
    setproperty node.mat prop value
)

“probably because DiffuseColor in your case is undefined. “

But I want to define DiffuseColor inside the function so the result would be

assign box Diffusecolor

reads as

box.material.DiffuseColor = color 150 150 150
1 Reply
(@denist)
Joined: 1 year ago

Posts: 0

in this case you don’t need to pass property, you only need a value

fn setNodeMaterialDiffuseColor node col = (node.mat.DiffuseColor = col)
-- setNodeMaterialDiffuseColor selection[1] red

Thanks, one last thing.
With my function I want to able to pass a property of the material, like specularmap, diffusemap,refractionmap and so on.

So the example function you wrote would be something like

fn setNodeMaterialDiffuseColor node matprop = (node.material.matprop = col 150 150 150)
-- setNodeMaterialDiffuseColor selection[1] specularmap

or

-- setNodeMaterialDiffuseColor selection[1] diffusemap

I guess maxscript is acting like the matprop argument is treated like a built-in property, and thus not recognizing it as a variable.
Maybe I’m heading to a non practical solution?