Search code examples
pythonmaxscript

Maxscript Python addModifier


I'm writing maxscript in python and the following code throws a type error:

import MaxPlus

res = MaxPlus.Core.GetRootNode()
#This is just as example that I use the first child.
child = MaxPlus.INode.GetChild(res,0)

morpherFP = MaxPlus.FPValue()
MaxPlus.Core.EvalMAXScript("Morpher()", morpherFP)
morpher = MaxPlus.FPValue.Get(morpherFP)

MaxPlus.INode.AddModifier(child, morpher)

And from the MaxScript Listener I always receive the following error:

type 'exceptions.TypeError' in method 'INode_AddModifier', argument 2 of type 'Autodesk::Max::Modifier'"

while the type of morpher is Animatable(Morpher) and Animatable is a subclass of Modifier. Could someone help me with this?

Thank you in advance


Solution

  • I think I found a possible solution (The only thing I know is that the MaxScript Listener doesn't throw an error):

    import MaxPlus
    
    res = MaxPlus.Core.GetRootNode()
    #I use the first child as example
    child = MaxPlus.INode.GetChild(res,0)
    morpher = MaxPlus.Factory.CreateObjectModifier(MaxPlus.ClassIds.Morpher)
    MaxPlus.INode.AddModifier(child, morpher) 
    # the following also seems to work aka it does not throw any errors
    child.InsertModifier(morpher,1)
    

    Let me know if it is not correct or there is an easier or more understandable way.