RSS FEED

Removing Controller with MAXScript

Since there's no built-in MAXScript function to remove controller once you add it to a parameter, here's a function to do that for you. Big thanks to Larry Minton for revealing how to handle ParamBlock2 PB2Values.

fn removeController subAnim = if isKindOf subAnim ::SubAnim and isController subAnim.controller do
(
    local originalValue = subAnim.value
    local REFMSG_CONTROLREF_CHANGE = 0xFA

    if isKindOf subAnim.parent ParamBlock2 then
    (
        local iGlobal = (dotNetClass "Autodesk.Max.GlobalInterface").Instance
        local pBlockNET = iGlobal.Animatable.GetAnimByHandle (getHandleByAnim subAnim.parent)
        local pValNET = pBlockNET.GetPB2Value (pBlockNET.IndexToId (subAnim.index - 1)) 0

        pValNET.Flags = bit.or pValNET.Flags 0x40 -- set the flag on the PB2Value which controls if the parameter is animated - this effectively removes the controller
    )
    else
    (
        local ctrl = subAnim.controller
        local parent = subAnim.parent
        local index = for i = 1 to refs.getNumRefs parent where refs.getReference parent i == ctrl do exit with i

        refs.replaceReference parent index undefined
    )

    if classOf subAnim.value == classOf originalValue do subAnim.value = originalValue
    notifyDependents subAnim.parent msg:REFMSG_CONTROLREF_CHANGE
)

A sample of usage shows how to remove a controller from a sphere's radius parameter:

Sphere radius:.5 isSelected:on
$.radius.controller = Bezier_Float()
removeController $.baseObject[#radius]

DISCLAIMER: All scripts and snippets are provided as is under Creative Commons Zero (public domain, no restrictions) license. The author and this blog cannot be held liable for any loss caused as a result of inaccuracy or error within these web pages. Use at your own risk.

This Post needs Your Comment!

Return to top