Sounds like you’ve got a number of problems here and I’m not sure which ones solves your problem, but I might be able to help you with this.
Usually it comes down to me not knowing how to “multiply” the matrix * the child object’s transform node In Maya, there’s an output on each transform node that carries it’s matrix; it’s called simply matrix. It’s also got inverseMatrix and worldMatrix which are self-explanatory. You can multiply these with a multMatrix <http://help.autodesk.com/cloudhelp/2015/ENU/Maya-Tech-Docs/Nodes/multMatrix.html> node, that you can create and connect like so: from maya import cmds multMatrix = cmds.createNode("multMatrix") # Connect to multMatrix cmds.connectAttr("moon.worldMatrix", multMatrix + ".matrixIn[0]") cmds.connectAttr("earth.worldMatrix", multMatrix + ".matrixIn[1]") At this point, multMatrix will contain the multiplied matrix. print cmds.getAttr(multMatrix + ".matrixSum")# [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0] You can convert the matrix back to translation values using decomposeMatrix, so that you can hook it back up to whichever node you are looking to drive. As for saving it out, you can export the multMatrix node and import it back in, it will still contain the values, although ideally you’d simply make it procedural and maintain the connections. But I must admit I’m not fully understanding what you’re trying to accomplish. Maybe if you break it down into one question at a time, we could get a little closer to a solution. Best, Marcus On 3 March 2015 at 22:30, V126 <[email protected]> wrote: > Hey guys, > > I'm a noob, and am trying to understand how to use the inverse matrix > better. It's related to this thread so I'm replying here. I've searched > through all the documentation and posts and haven't found an answer (that I > can fully comprehend) yet. > > My previous experience comes from maxscript, so I'll have to use it as > pseudocode to illustrate. > > I've got three objects with transform nodes: "moon", "earth" and > "asteroid1". I want to save the translation and rotation of "moon" relative > to "earth" into a variable, so I can snap "asteroid1" to that exact > translation and rotation that the moon has, relative to the "earth". I want > to save it in a variable so I can use that relative position and rotation > in another file that doesn't have the "moon" in it (therefore I can't cheat > and just xform "asteroid1" to "moon"). > > Here's how I did this in maxscript pseudocode: > > # Get a transformation matrix of the “moon” to the “earth”. > > my_matrix = moon.transform * inverse earth.transform > > # Then use that matrix to snap the “asteroid1” to the location I recorded > relative to the “earth” in worldspace. > > In coordsys world > > ( > > asteroid1.transform = my_matrix * earth.transform > > ) > > In 3DS Max, that would snap "asteroid1" to where "moon" was relative to > the "earth". As a bonus, I'd love the option of being able to snap ONLY > "asteroid1"'s translation OR ONLY it's rotation if I so choose. > > I've tried using maya's xform and getAttr commands. I've also tried some > OpenMaya commands suggested by a friend, like .MTransformationMatrix(), and > .asMatrixInverse(), but I don't have enough experience to know how to get > the result I'm looking for. Usually it comes down to me not knowing how to > "multiply" the matrix * the child object's transform node. I'm eager to > learn how to use the MfnTransform and inclusiveMatrix, but I don't have a > good jumping off point. The simpler solution the better for me. > > Any advice would be appreciated! > > Thanks > > > On Monday, August 2, 2010 at 6:07:30 PM UTC-7, kungFu_Teddy wrote: >> >> Yep, I think the better and faster way it's MfnTransform and >> inclusiveMatrix :) >> >> -------------------------------- >> Marco D'Ambros >> phone : (+61) 0431 830085 >> mail : [email protected] >> wave : [email protected] >> >> >> >> On Tue, Aug 3, 2010 at 6:40 AM, Chad Vernon <[email protected]> wrote: >> >>> You can get matrices with MDagPath::inclusiveMatrix or exclusiveMatrix. >>> To set a matrix, you can use MFnTransform. The MPx* classes are proxy >>> classes that you only use when creating a custom object like a node or >>> context. >>> >>> Chad >>> >>> >>> >>> >>> On Mon, Aug 2, 2010 at 1:05 PM, johnvdz <[email protected]> wrote: >>> >>>> Hi all, >>>> >>>> i have a script that calculates per vertex tangent space and constructs >>>> a matrix. which all works fine but now i'm just looking at trying to get it >>>> to work in a global position. >>>> >>>> what is the best way in Api to get the objects Inverse Square matrix or >>>> an object? there seems to be a few options whats the deference >>>> >>>> >>>> *MPxTransformationMatrix* <cid:[email protected]> () >>>> >>>> *MPxTransform* <cid:[email protected]> () >>>> >>>> any guidance would be great >>>> >>>> john >>>> >>>> -- >>>> http://groups.google.com/group/python_inside_maya >>> >>> >>> -- >>> http://groups.google.com/group/python_inside_maya >>> >> >> -- > You received this message because you are subscribed to the Google Groups > "Python Programming for Autodesk Maya" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/python_inside_maya/29fe8851-9e8a-49df-afcb-f32cc4b35abf%40googlegroups.com > <https://groups.google.com/d/msgid/python_inside_maya/29fe8851-9e8a-49df-afcb-f32cc4b35abf%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- *Marcus Ottosson* [email protected] -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOBFKsDKG5n_LzbzNHfouqdW4xuTN8-Gc4uEQHENC7JkOg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
