Add Force to the Spring


#1

When I add force to the spring I got the error:

delete objects
clearlistener()
Obj = teapot isselected:true
SC = Obj.position.controller = SpringPositionController()
append SC.forcenode (gravity())
	
-- Runtime error: Array parameter size fixed, cannot append: forceNode

Any trick to fix this? Maybe by using Autodes.max and twerking jiggle class?


#2

yep… it is possible

delete objects
gc()

spc = SpringPositionController()
spc.forceNode

g = (dotNetClass "Autodesk.Max.GlobalInterface").Instance
anim = g.animatable.GetAnimByHandle (dotNetObject "system.uintptr" (getHandleByAnim spc))
	
gr = gravity()
	
INode = g.coreinterface.getinodebyhandle gr.inode.handle
pb = anim.getparamblock 1
pb.Append (pb.indexToID 0) 1 INode 0
Obj = teapot isselected:true
Obj.position.controller = spc
spc.forceNode

#3

– Runtime error: .NET runtime exception: Unable to cast object of type ‘Autodesk.Max.Wrappers.INode’ to type ‘Autodesk.Max.Wrappers.ReferenceTarget’.


#4

Oh, indeed… works in 2014 but not in 2020.
You can compile c# dll and try it that way. Sometimes it helps and sometimes not. :expressionless:
I couldn’t make it work on the mxs side.


#5
using System;
using Autodesk.Max;

public class MyClass
{
    static IGlobal globalInterface = GlobalInterface.Instance;
    static IInterface coreInterface = globalInterface.COREInterface;

    public static void AddForceToSpring(UIntPtr springHandle, uint forceNodeHandle)
    {
        IAnimatable spring = globalInterface.Animatable.GetAnimByHandle(springHandle);
        IINode forceNode = globalInterface.COREInterface.GetINodeByHandle(forceNodeHandle);
        spring.GetParamBlock(1).Append(1,1,forceNode,0);
    }
}

This doesn’t work either.