Notifications
Clear all

[Closed] pymxs – Assign a new controller to an object

Hello,

I am having a bit of a tough time figuring out how to assign or even replace a controller on an objects transform controller using pymxs.

The below code presumes the selected object has had it’s transforms frozen:

import pymxs as mxPy
mxRt = mxPy.runtime

#Get selected object:
obj            = mxRt.selection[0]
print(obj)

#Get selected objects position controller
Ctrl_Position  = mxRt.getSubAnim(obj.controller, "position").controller
print(Ctrl_Position)

#Get the available subAnim from the controller:
Ctrl_Available = mxRt.getSubAnim(Ctrl_Position, "available")
print(Ctrl_Available)

#Define a new Position_XYZ controller:
Ctrl_PosXYZ    = mxRt.Position_XY()

#Try to assign the Position_XYZ controller as the subAnim controller in a maxscript like way:
Ctrl_Available.controller = Ctrl_PosXYZ
#Try to assign the Position_XYZ controller as the subAnim controller using setmxsprop:
isControlAdded = Ctrl_Available.setmxsprop("Controller", Ctrl_PosXYZ)
#Print output of setmxsprop:
print(isControlAdded)

I can’t seem to figure this out without running maxscript code through python or using maxPlus ( which I am specifically not using for the sake of this test ).
Has anyone been able to figure this out?

1 Reply

Hi I found something that might help !

rt.AddListController(myObj,“position”,“position_script”)

1rst Entry: the object you want to change the controller in
2nd Entry: the controller you want to change aka the old controller
3rd Entry: the new controller you want to assign

Hope it helps !

Cheers

Yann