Notifications
Clear all

[Closed] Add Force to the Spring

 MZ1

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?

4 Replies

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
 MZ1

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

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.
I couldn’t make it work on the mxs side.

 MZ1
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.