maxscript command for aligning 2 objects

maxscript command for aligning 2 objects

Anonymous
Not applicable
9,668 Views
14 Replies
Message 1 of 15

maxscript command for aligning 2 objects

Anonymous
Not applicable
can anyone help me with finding the maxscript command for aligning 2 objects. The macro recorder doesn't seem to record the actions of the align tool

Thanks
9,669 Views
14 Replies
Replies (14)
Message 2 of 15

Anonymous
Not applicable
You can align using this:

-- Align selection one to selection two
selection.transform = selection.transform

or

-- by objects
$obj_2_align.transform = $obj_2_align_2.transform

I'm sure I've seen a thread on this subject before, but I didn't manage to find it atm. Hope this helps anyways.

BR
MrK
0 Likes
Message 3 of 15

Anonymous
Not applicable
thanks for that mrk 🙂

just had to bit of fiddling around to work out how to get the objects from my array to pass through the command to align them, I used "getnodebyname" in the end.

The working version of the script is below. It's for setting up face bones for a biped based on helper positions exported from maya.

Just need to add all the rest of the joints and parent them to the biped head bone, maybe set some joint colours too 🙂


fn CreateFaceBones parent target =
(
for i = 1 to target.count do
(
data = filterString target ","
locator = data
joint = data



$
(
bonesys.createbone
).name = joint


joint_obj = getnodebyname joint
locator_obj = getnodebyname locator

--print joint_obj.name
--print locator_obj.name

joint_obj.transform = locator_obj.transform

)
)

CreateFaceBones "object" #("Point01,jaw", "Point02,left_cheek", "Point03,right_eye")
0 Likes
Message 4 of 15

paulneale
Advisor
Advisor
Your definitely a Maya user. I can tell that because you are using strings to get objects that you already have. when you create the bone assign it to a variable, that variable will hold reference to that object directly. This is great as the name could change and it will not matter to the code. Also this code has a whole lot of errors in it and will not run. please next time put the code in code tags so it keeps its formatting as well, just make it easier to help you.

fn CreateFaceBones target =
(
for i = 1 to target.count do
(
data = filterString target ","
locator = data
joint = data

joint_obj=bonesys.createbone
joint_obj.name = joint

locator_obj = getnodebyname locator
if not isValidNode locator_obj then (locator_obj =point pos:(random ) size:1 name:locator)

joint_obj.transform = locator_obj.transform
joint_obj.parent=locator_obj
)
)

CreateFaceBones #("Point01,jaw", "Point02,left_cheek", "Point03,right_eye")
Paul Neale

http://paulneale.com


Paul Neale




EESignature

Message 5 of 15

Anonymous
Not applicable
thanks for your help Paul, getting a bit clearer - our heads are still full of mel and python here 🙂

I just changed the line below to parent the created bones to the head

joint_obj.parent= $head
0 Likes
Message 6 of 15

paulneale
Advisor
Advisor
Something to note, .transform is doing the whole transform matrix and not just the position and rotation, so it is also getting any scale values. Realistically there shouldn't be any scale values on the locators that you are importing but if there is you might not want the scale propagated to the bones so do this instead..

joint_obj.rotation = locator_obj.rotation
joint_obj.pos = locator_obj.pos


Make sure you do the rotation first.
Paul Neale

http://paulneale.com


Paul Neale




EESignature

Message 7 of 15

Anonymous
Not applicable
Is there a way to do:

$obj_2_align.transform = $obj_2_align_2.transform 


but tell it to ignore the scale portion of .transform?

I tried

joint_obj.rotation = locator_obj.rotation
joint_obj.pos = locator_obj.pos


as suggested by penn but that doesn't work (first command rotates around world and not the correct rotation, is there a way to tell it to rotate locally?)

Basically I want to do what the align dialog box says in the attached image:
0 Likes
Message 8 of 15

Anonymous
Not applicable
The cool thing with ".transform" is that it works no matter what the animation controllers are, you can set that property on a biped for example.

Maybe the simplest thing is to copy the transform and then put back the original scale (hoping the controller is the same for the scale).

Or you can specify that you want to transform in a given space with for example

in coordsys local a.pos = b.pos
in coordsys parent a.rotation = b.rotation

etc.

Hope this helps!
0 Likes
Message 9 of 15

Anonymous
Not applicable
or just use ".transform.rotation" instead of ".rotation"
0 Likes
Message 10 of 15

Anonymous
Not applicable
When I do..

selection.transform.position = selection.transform.position
selection.transform.rotation = selection.transform.rotation

returns:
(quat 0 0 0.861702 0.507415)


nothing moves, thoughts?

p
0 Likes
Message 11 of 15

paulneale
Advisor
Advisor
You can't set the transform.position property you need to just use .pos or .position.
Paul Neale

http://paulneale.com


Paul Neale




EESignature

0 Likes
Message 12 of 15

info
Contributor
Contributor
Hello Community,

what about aligning an object's minimum/ maximum to another object's extents?

Kind regards
Arnim
0 Likes
Message 13 of 15

paulneale
Advisor
Advisor
I suggest that you start a new thread as I last responded to this in 2009.

When you do explain exactly what it is you are trying to do.
Paul Neale

http://paulneale.com


Paul Neale




EESignature

0 Likes
Message 14 of 15

info
Contributor
Contributor
OK. I just was afraid, that someone would mind, that I do not search the existing threads (some forums are much more restrictive than The Area is).

Kind regards
Arnim
0 Likes
Message 15 of 15

Anonymous
Not applicable

Hi! Maybe you know the way to align 2 object exactly like maxalign tool. Becouse i have many situations, when transform result from script are different with maxalign..

Thxs

0 Likes