>
>
> 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

-- 
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/CAGq9Q7FiwHPT_%2Bs228Z20BG_ObXS1Nh7yOVR4058S8Sk7vhTrw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to