A question about MAXScript

A question about MAXScript

panghsheng
Explorer Explorer
910 Views
9 Replies
Message 1 of 10

A question about MAXScript

panghsheng
Explorer
Explorer

I want to implement a functionality where, in the currently active SME view, I search for all VRayMtl nodes. If found, I check if the node connected to the diffuseMap port is a VRayBitmap. If it is, I modify coords.blur to 0.01. If not, I traverse all output ports of the material until I find a VRayBitmap and set its coords.blur to 0.1. Below is my code, but I don't know why it's throwing errors.

function setVRayBitmap m =
(
    diffuseMap = m.diffuseMap
    if isKindOf diffuseMap VRayBitmap do
    (
        diffuseMap.coords.blur = 0.01
    )
    if not isKindOf diffuseMap VRayBitmap do
    (
        for i = 1 to m.numOutputs() do
        (
            outputMap = m.getOutputMap i
            if isKindOf outputMap VRayBitmap do
            (
                outputMap.coords.blur = 0.01
               return
            )
        )
    ) 
)

function SMEGetMatsInView = 
(    
    viewNode = sme.GetView (sme.activeView)
    for n = 1 to trackViewNodes[#sme][(sme.activeView)].numSubs do 
    (
        m = trackViewNodes[#sme][(sme.activeView)][n].reference
        if classOf m == VRayMtl do 
        (
            setVRayBitmap m
        )
    )
)

SMEGetMatsInView()
0 Likes
911 Views
9 Replies
Replies (9)
Message 2 of 10

denisT.MaxDoctor
Advisor
Advisor

@panghsheng wrote:

 Below is my code, but I don't know why it's throwing errors.


What is this, a game? Do we have to guess the errors first and then tell you how to fix them?

0 Likes
Message 3 of 10

panghsheng
Explorer
Explorer

Thank you for your reply.

0 Likes
Message 4 of 10

panghsheng
Explorer
Explorer

Thank you for your reply. This is not a game. I want to batch change the parameters of VRayBitmap, as shown in the figure below. In the currently active view window of SME, I want to batch change the value of coords.blur of VRayBitmap. However, the value depends on which port it is in VrayMtl. If it is under diffuseMap, the value of coords.blur of VRayBitmap is 0.1. If it is under reflectionMap, the value of coords.blur of VRayBitmap is 0.01. Or if it is under BumpMap, the value is 0.03.dd3cda8b4e0e1267369de7d39a0f1fe.png

0 Likes
Message 5 of 10

denisT.MaxDoctor
Advisor
Advisor

post the error messages you get... screenshots of the message box and the log from the listener

0 Likes
Message 6 of 10

panghsheng
Explorer
Explorer

Okay, thanks again for your response。:)692681fabefaf57f379ef8615b83911.png

0 Likes
Message 7 of 10

denisT.MaxDoctor
Advisor
Advisor

at line 16 of your code should be

 

return ()

 

this is why you should post "errors"... 

 

 

0 Likes
Message 8 of 10

panghsheng
Explorer
Explorer

This is the result after adding parentheses. I suspect there might be an issue with the logic of the entire code.cfd6aa3bc564dbcda31b469fd38b547.png

0 Likes
Message 9 of 10

denisT.MaxDoctor
Advisor
Advisor

the error log tells you everything... "in line 10 the material doesn't have a method or property #numOutputs"

so see the documentation on how to get the correct number of VRay material outputs

0 Likes
Message 10 of 10

denisT.MaxDoctor
Advisor
Advisor

Step by step, we'll first correct all the syntax errors, then move on to the logical ones... and then, possibly, to the stylistic ones.

0 Likes