[Maya-Python] MNodeMessage for Attributes?

570 views
Skip to first unread message

Judah Baron

unread,
May 6, 2010, 10:26:11 PM5/6/10
to python_in...@googlegroups.com
Does anyone have a good way of monitoring the deletion of a secific attribute? MNodeMessage.addNodePreRemovalCallback doesn't like attributes. It works nicely for dg/dag nodes, but gives kInvalidParameter for attribute mobjects.

-Judah

--
http://groups.google.com/group/python_inside_maya

Ryan

unread,
May 7, 2010, 11:37:30 AM5/7/10
to python_inside_maya
Use MNodeMessage.addAttributeChangedCallback

id = OpenMaya.MNodeMessage.addAttributeChangedCallback(node, func,
clientData)


create a callback method (that you pass as to func above) like

def attributeChangedCallback(self, msg, mplug, otherMplug,
clientData):

nodeName, attrName = mplug.name().split('.')
if msg & OpenMaya.MNodeMessage.kAttributeRemoved:
print 'attr %s on node %s was removed' % (attrName, nodeName)




Ryan
--
http://groups.google.com/group/python_inside_maya

Judah Baron

unread,
May 7, 2010, 8:23:35 PM5/7/10
to python_in...@googlegroups.com
I think I'm going to have to go another route. The attribute change callback is triggered for any changing attribute on the node, which could be quite a lot in this particular case. I will have to monitor the association, which is a little more complex structurally, but will be a lot more efficient in the end. These attributes are referred to by another node, so I'll use MDGMessage.addConnectionCallback to track their removal.
--
http://groups.google.com/group/python_inside_maya

Shaun Friedberg (Pyrokinesis)

unread,
May 8, 2010, 7:42:43 AM5/8/10
to python_in...@googlegroups.com

Hello,

I have been recently inspired to learn more about Quaternion’s. I understand the basics but I would like to learn more about implementing them in context in Python and Maya.

Does anyone know of examples floating around?

 

Thanks.

 

--
http://groups.google.com/group/python_inside_maya

Xavier Ho

unread,
May 8, 2010, 10:48:37 AM5/8/10
to sh...@pyrokinesis.co.nz, python_in...@googlegroups.com
On Sat, May 8, 2010 at 9:42 PM, Shaun Friedberg (Pyrokinesis) <sh...@pyrokinesis.co.nz> wrote:

Hello,

I have been recently inspired to learn more about Quaternion’s. I understand the basics but I would like to learn more about implementing them in context in Python and Maya.

Does anyone know of examples floating around?

 

Thanks.

Hey there,

I looked into quaternions about half a year ago, and implemented it for the first time in Python. I'm thinking about rewriting the code now, but my first version might be helpful for you to look at. Or use it, either way.

You can probably take the idea and optimise/improve on it, too.

http://pastebin.com/CNQDvqHF

By the way, I really recommend these articles linked in a recent post I wrote on Stackoverflow:

http://stackoverflow.com/questions/2758501/rotating-in-opengl-relative-to-the-viewport/2758673#2758673

HTH & Have fun,
Xav

(P.S: I'm not too sure if my emails are actually going through. Can someone reply and let me know? Thanks.)

--
http://groups.google.com/group/python_inside_maya

Ozgur Yılmaz

unread,
May 8, 2010, 12:24:45 PM5/8/10
to python_in...@googlegroups.com
as far as I know there is an MQuaternion class in the python API, so there is no need to develop another one...

cheers

E.Ozgur Yilmaz
Lead Technical Director
www.ozgurfx.com
--
http://groups.google.com/group/python_inside_maya

Adam Mechtley

unread,
May 8, 2010, 12:33:04 PM5/8/10
to python_in...@googlegroups.com
Not sure if it was Shaun's intent, but to be totally fair, I would say there is little need to develop another one, rather than no need :)

Some parts of the MQuaternion class (e.g. slerp) are not accessible to Python, and some other functions (e.g. slime) are not present. In such cases, though, you can quite easily add your own functions to the MQuaternion class and use its existing functionality for everything else.
--
http://groups.google.com/group/python_inside_maya

Shaun Friedberg (Pyrokinesis)

unread,
May 10, 2010, 8:46:48 AM5/10/10
to python_in...@googlegroups.com

Thanks everyone, Its true I’m not going to be developing for the API.

From what I can tell so far Quaternion’s are a really great way to work with rotations in moderation.

Apparently once you get more than 10 or so translations deep, the math gets pretty intense.

I’m looking forward to learning more, and If I learn anything worth sharing, I’ll be sure to post here.

 

Thanks.

--
http://groups.google.com/group/python_inside_maya

Xavier Ho

unread,
May 10, 2010, 9:25:17 AM5/10/10
to python_in...@googlegroups.com
On Mon, May 10, 2010 at 10:46 PM, Shaun Friedberg (Pyrokinesis) <sh...@pyrokinesis.co.nz> wrote:

Apparently once you get more than 10 or so translations deep, the math gets pretty intense.


I'm not sure what you mean by that, Shaun. If you're only using Quaternions for rotation, (which is why it's uesful for in 3D), there are only about 3 ways to do it. The most popular way is the "sandwich".

If Q is a quaternion, and Qc is its conjugate (w, -x, -y, -z), then the rotation is basically:

Q * vector * Qc.

Where the multiplication is the Quaternion multiplication.

Then you only really need two other things:
 - How to convert rotation to quaternions
 - How to convert qutations back to xyz coordinates.

That's about it. Most of the translations build up from these principles, so they shouldn't get "deeper" or "intense". And many websites describe how to perform these tasks.

(Although, if you're going anywhere deeper than that, then yes, it gets pretty intense. Starting with 4D spacial rotation, which I haven't had the time to look into..)

Have fun and good luck!

Cheers,
Xav

--
http://groups.google.com/group/python_inside_maya
Reply all
Reply to author
Forward
0 new messages