MaxScript - Setting Rotate Transform Type-in values via script?

MaxScript - Setting Rotate Transform Type-in values via script?

irisw4
Explorer Explorer
4,428 Views
1 Reply
Message 1 of 2

MaxScript - Setting Rotate Transform Type-in values via script?

irisw4
Explorer
Explorer

Hi,

 

I need some help creating a Maxscript for transferring bone rotation values from one model (a reference model that's already fully rigged and animated) to another. Basically, what I want to do is copy the XYZ rotation values you'd find at the bottom of 3ds max (the Rotate Transform Type-in values for Absolute:World) from one bone to the bone of another model. There are a lot of keyframes... fun times 🙃  So I am looking to Maxscript to automate this copy and paste tedium.

 

I managed to get the rotation values I want from the Transform Type-in (or something close enough that will work on a practical level) by using

 

 

local testrotation = in coordsys world quatToEuler2 obj.transform.rotation;
print testrotation;

 

 

But what should I do to set the values in the Rotate Transform Type-in via Maxscript?

 

local xRotation = testrotation.x;
selected.rotation.x_rotation = xRotation;

 

 

When I tried setting it using obj.rotation, it didn't work since .rotation takes in a quat and not a eulerAngle, and converting testrotation from a eulerAngle to a quat beforehand didn't work either.

 

Using "selected.transform.rotation = testrotation as quat" didn't work either.

 

I am probably either misunderstanding something, or I overlooked something very obvious.

 

I appreciate any help anyone could give. Thanks in advance!

0 Likes
Accepted solutions (1)
4,429 Views
1 Reply
Reply (1)
Message 2 of 2

leeminardi
Mentor
Mentor
Accepted solution

Working with rotations in 3D is tricky.  The xyz rotations you see in the transform type-in are not the angles you need to rotate from a base world rotation of  x = 0, y = 0, z = 0 but the result of several rotations about different axes in a specific order.   The angles you see are the final orientation of the object.

 

Rather than use angles I would suggest you just copy the transform from the reference bone to the bone you want to reorient while keeping the position of the latter.

 

For example, let’s say I would like to give bone009 the 3D orientation of bone003.  The following script would accomplish this.

m9 =  $bone003.transform
m9.pos = $bone009.position
$bone009.transform = m9

 

lee.minardi
0 Likes