how to inherit transform class fropm pymel

507 views
Skip to first unread message

ynedelin

unread,
Jun 20, 2012, 6:30:00 PM6/20/12
to python_in...@googlegroups.com
hey Guys
I think I am totally thinking wrong about this, please explain.

so I would like to inherit the nt.Transform and i am not sure how to do it.

for example can I do this?

import pymel.core as pm
class MyTrans(pm.nt.Transform):
   t = "test"

n = MyTrans("pCube1")
#does not work

I am trying to do this:
Let say I have a rig control and it is a Maya transform but it also has a bunch of my rig specific info on it like custom attributes.
I would like to make a class for this control that could be used to quickly get info about it or perform different functions on it.

so i can do thinks like

n = MyTrans("ctrl1")
n.getRotation() #from nt.Transform
and
n.getBodypart() #added by me

thanks
Yury






Paul Molodowitch

unread,
Jun 20, 2012, 10:09:40 PM6/20/12
to python_in...@googlegroups.com
Hi Yury - what you're looking for is pymel "virtual classes" - there's an example here:


Or, Jason Parks has kindly written up a nice little tutorial:


Let me know if there's anything you have questions about!

 - paul

yury nedelin

unread,
Jun 21, 2012, 1:48:47 PM6/21/12
to python_in...@googlegroups.com
Thanks Paul
I will look at these today
Yury

David Lantos

unread,
Feb 20, 2014, 9:54:26 AM2/20/14
to python_in...@googlegroups.com
Hi Guys!

The tutorial is about how to create subclass for nodes.
What if I want to inherit pymel.core.Attribute class for my subclass?

David

Chad Dombrova

unread,
Feb 20, 2014, 1:02:03 PM2/20/14
to Maya Python Group

The tutorial is about how to create subclass for nodes.
What if I want to inherit pymel.core.Attribute class for my subclass?

the advantage of virtual classes is deep integration: you register your new virtual node class -- which also tells pymel how to identify nodes that should be cast to this type -- and pymel's core commands will casts the appropriate nodes to instances of your class.

virtual classes are not currently supported for Attributes.  it's also not straightforward to directly subclass pymel nodes and attributes, because at the lowest level the PyNode class performs a type check on instantiation.  This allows you to do type assertions when you directly instantiate a node type class. for example, here i'm asserting that I want a DAG node, but i've stupidly given it a depend node as an argument:

pm.nt.DagNode('lambert1')
# Error: Determined type is Lambert, which is not a subclass of desired type DagNode
# Traceback (most recent call last):
#   File "<maya console>", line 1, in <module>
#   File "/Volumes/sv-dev01/devRepo/chad/python/pymel/pymel/core/general.py", line 1943, in __new__
#     raise TypeError, "Determined type is %s, which is not a subclass of desired type %s" % ( pymelType.__name__, cls.__name__ )
# TypeError: Determined type is Lambert, which is not a subclass of desired type DagNode # 

This same, low-level check prevents this from working:

class MyFloatAttribute(Attribute):
    def somethingDumb(self):
        print self.get() + 2.0

at = MyFloatAttribute('persp.tx')
# Error: Determined type is Attribute, which is not a subclass of desired type MyFloatAttribute
# Traceback (most recent call last):
#   File "<maya console>", line 5, in <module>
#   File "/Volumes/sv-dev01/devRepo/chad/python/pymel/pymel/core/general.py", line 1943, in __new__
#     raise TypeError, "Determined type is %s, which is not a subclass of desired type %s" % ( pymelType.__name__, cls.__name__ )
# TypeError: Determined type is Attribute, which is not a subclass of desired type MyFloatAttribute # 

You might consider using a "has-A" object-oriented design, rather than an "is-A".  in other words, you special class has an attribute on it which it uses to perform its specialized function, rather than actually being an attribute.

-chad





Paul Molodowitch

unread,
Feb 21, 2014, 12:15:36 PM2/21/14
to python_inside_maya
Though... it probably wouldn't be hard to extend the basic concepts behind virtual (node) subclasses to attributes.  The potential audience seems much smaller than for virtual nodes, though... so unless there's large demand, I don't think it's anything we'd implement anytime soon.
If anyone wants to take a whack at implementing it themselves, we're open to submissions! =)


--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAGq9Q7FiwHPT_%2Bs228Z20BG_ObXS1Nh7yOVR4058S8Sk7vhTrw%40mail.gmail.com.

For more options, visit https://groups.google.com/groups/opt_out.

David Lantos

unread,
Feb 21, 2014, 4:12:41 PM2/21/14
to python_in...@googlegroups.com
Thank you guys the answers.
I have developed a big-system in pymel, and I would just like to use the advatage of pymel and I think I will write more wrappers top of it. If something is good why change it or rewrite, do I?
I mean the class, pymel.core.Attribute is well-designed (I mentioned in previous mail) so it's not worth to rewrite a new class just because I want to extend it.
Later I will jump into pymel more deep, but now I do not know a lot about it, how was built in deep layer. Probably I will attept to develope this staff.

David
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages