python equivalent for $.transform.Rotation
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone! First message to the forum here so hopefully this will be the right place to ask these type of questions 🙂
I've spent few days playing with 3dsMax 2018 python API and the experience has been great so far (I'm amazed with the great job Autodesk engineers have put into this one, hats off) but right now I've got stuck with an issue here and after spending couple of days trying to figure it out I've decided to ask directly here.
In order to reproduce my problem follow the next steps:
- 1) Create a box in position [-40,0,0], rotation [25,35,45] and scaling [110,120,130] and select it
- 2) Open a maxscript listener and check some values first about the selected node:
$.Transform.Position [-40,0,0] $.Transform.Scale [1.1,1.2,1.3] $.Transform.Rotation as eulerAngles (eulerAngles 25 35 45) $.Transform.Rotation (quat -0.0783618 -0.350225 -0.29619 0.88514) quat -0.0783618 -0.350225 -0.29619 0.88514 as EulerAngles (eulerAngles 25 35 45)
So far so good, everything is ok and makes sense... now, let's try to capture the same information of the selected node using Python API:
-3 Create a new python script and paste the below code:
def run_mxs(code):
res = MaxPlus.FPValue()
MaxPlus.Core.EvalMAXScript(code, res)
return MaxPlus.FPValue.Get(res)
print('-'*80)
print("$.transform.Rotation", str(run_mxs("$.transform.Rotation")))
print("$.transform.Position", str(run_mxs("$.transform.Position")))
print("$.transform.Scale", str(run_mxs("$.transform.Scale")))
for node in MaxPlus.SelectionManager.GetNodes():
# print("node.parent",node.Parent)
print("node.LocalRotation", str(node.LocalRotation))
print("node.LocalPosition", str(node.LocalPosition))
print("node.LocalScaling", str(node.LocalScaling))
print("node.Rotation", str(node.Rotation))
print("node.Position", str(node.Position))
print("node.Scaling", str(node.Scaling))
print("node.LocalTM.Rotation", str(child.GetLocalTM().Rotation))
If you run it you should get this output:
--------------------------------------------------------------------------------
('$.transform.Rotation', 'Quat(-0,0783618, -0,350225, -0,29619, 0,88514)')
('$.transform.Position', 'Point3(-40, 0, 0)')
('$.transform.Scale', 'Point3(1,1, 1,2, 1,3)')
('node.LocalRotation', 'Quat(-0,0862001, -0,395834, -0,317373, 0,945647)')
('node.LocalPosition', 'Point3(-40, 0, 0)')
('node.LocalScaling', 'Point3(1,1, 1,2, 1,3)')
('node.Rotation', 'Quat(-0,0862001, -0,395834, -0,317373, 0,945647)')
('node.Position', 'Point3(-40, 0, 0)')
('node.Scaling', 'Point3(1,1, 1,2, 1,3)')
('node.LocalTM.Rotation', 'Quat(-0,0862001, -0,395834, -0,317373, 0,945647)')
QUESTION: Why is the Quaternion coming from python API different from the Quaternion from Maxscript? Is this a bug in the Python API? If it's not... how would you get the "correct" quaternion using the python API? When I say "correct" I mean the one equivalent to eulerAngles(25,35,45) ?
Thanks in advance!