Notifications
Clear all

[Closed] Newb – Maxscript Error When Selecting Object

I’m trying to write a maxscript that will create a custom modifier. That modifier will point the normals of the applied object toward the center of a selected object. Here’s my code:

plugin modifier MyModifier
name:"My Modifier"
classID:#(0x12345678, 0x87654321)

(
    parameters main rollout:params
    (
        pickedObject type:#node ui:pickedObjectButton
    )

    rollout params "My Modifier Parameters"
    (
        button pickedObjectButton "Pick Object" width:100 align:#center
    
        on pickedObjectButton pressed do
        (
            pickedObject = pickObject prompt:"Select an object to use"
            if pickedObject != undefined do update()
        )
    )

    on preRender do
    (
        if pickedObject != undefined do
        (
            if (selection.count > 0) do
            (
                obj = selection[1]
                convertToMesh obj
                meshData = snapshotasmesh obj
                verts = meshData.verts
                faces = meshData.faces
                normals = #()
                for f in faces do
                (
                    p1 = verts[f.x]
                    p2 = verts[f.y]
                    p3 = verts[f.z]
                    norm = normalize (cross (p2 - p1) (p3 - p1))
                    append normals norm
                )
                pickedPos = pickedObject.transform.row4
                for i = 1 to normals.count do
                (
                    face = getFace obj i
                    norm = normals[i]
                    center = (verts[face.x] + verts[face.y] + verts[face.z]) / 3.0
                    dir = normalize (pickedPos - center)
                    newNorm = normalize (norm + dir)
                    setFaceNormal obj i newNorm
                )
                update obj
            )
        )
    )
) 

This creates the modifier with a button to select an object in the scene, but when I try clicking on an object I get this:

Select an object to use
– Error occurred in anonymous codeblock; filename: C:\Users\JSwanson\OneDrive – S-E-A\Desktop\New folder (3)\Maxscripts\Test.ms; position: 504; line: 18
– MAXScript Rollout Handler Exception:
– Argument count error: generic apply wanted 1, got 0
– MAXScript callstack:
– thread data: threadID:42636


– [stack level: 0]
– In pickedObjectButton.pressed(); filename: C:\Users\JSwanson\OneDrive – S-E-A\Desktop\New folder (3)\Maxscripts\Test.ms; position: 505; line: 18
– member of: Rollout:params
– Locals:
– Externals:
– params: Rollout:params
– pickedobject: PluginParameter:pickedobject : $Target_Sphere:TPhotometricLight001 @ [1.824579,67.816650,79.362770]
– owner: Rollout:params


– [stack level: 1]
– called from top-level

What am I doing wrong?

2 Replies

update() >> update $
No error

That did fix the error. Still some work to do to get the whole thing working, but I’m at least over this hurdle.

Thanks!