Thanks Seth!  Again, I'm using pymel that comes with 2011
pymel.__version__ == 1.0.0'

I was able to get a small working example that works with pm.createNode:

class MyNode(pm.nt.MyNode):
    @classmethod
    def _isVirtual( cls, obj, name ):
        return True

    def test(self):
        print 'MY NODE!'

pymel.internal.factories.registerVirtualClass(MyNode)

myNode = pm.createNode('MyNode')
myNode.test()


Although, I'd like to be able to create my nodes via a call to
MyNode().  To do this I added the classmethod createVirtual:

class MyNode(pm.nt.MyNode):
    @classmethod
    def createVirtual(cls, **kwargs):
        print 'CREATING MY NODE!'
        return pm.createNode('MyNode', **kwargs)

    @classmethod
    def _isVirtual( cls, obj, name ):
        return True

    def test(self):
        print 'MY NODE!'

myNode = MyNode()
# Error: ValueError: unexpect result locator1 returned by spaceLocator #

Am I missing something here?

Thanks,
Justin

On Tue, Nov 1, 2011 at 12:24 AM, Justin <[email protected]> wrote:
> Thanks!  The first example seemed a bit overkill which is why I asked the 
> question, but the second example is exactly what I need (Except I'm not on 
> the trunk):
>
> # make sure Mayatomr plugin is loaded ore the Mib_amb_occlusion might not 
> exist
> loadPlugin('Mayatomr')
> class Mib_amb_occlusion(Mib_amb_occlusion):
>    """This is an example of how to replace a node.  Use this technique with 
> care"""
>    def occlude(self):
>        print "occluding!"
>
> # the callback always returns True, so we always replace the default with our 
> own.
> Mib_amb_occlusion.registerVirtualSubClass( lambda *args: True, 
> nameRequired=False )
>
> def testMib():
>    n = createNode('mib_amb_occlusion')
>    n.occlude()
>
> But, I get the following error:
> # Error: AttributeError: file 
> /Applications/Autodesk/maya2011/Maya.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages/pymel/core/general.py
>  line 53: type object 'Mib_amb_occlusion' has no attribute '_isVirtual' #
>
> I'm running the version of pcl that comes with 2011.  I assume there have 
> been a bunch of changes since then that has made this process easier, not 
> requiring _isVirtual to be defined or in the trunks case a callback to be 
> specified?  Can I accomplish the same task of replacing the mental ray node 
> with the version of pcl that comes with Maya2011?
>
> Thanks,
> Justin
>
>
> On Oct 31, 2011, at 11:53 PM, Justin Israel wrote:
>
>> This seems to be a really straight forward example located here:
>> http://pymel.googlecode.com/svn/trunk/examples/customClasses.py
>>
>> It outlines how to subclass, and what class methods must be provided. I 
>> believe the use of the id attribute is for the validation test function, in 
>> order to determine if the incoming object type is the right kind. In this 
>> case they use the joint id attribute from the original Joint class to check. 
>> If its a joint then allow this subclass to be returned. Technically you 
>> could perform any test you see fit as long as you stick to the api to do it 
>> and not pymel calls.
>>
>>
>>
>>
>> On Oct 31, 2011, at 7:51 PM, Justin <[email protected]> wrote:
>>
>>> Hey all, It's been a super long time since I've been on this list!
>>>
>>> I was wondering if I could get a quick example on how to accomplish a 
>>> simple wrapping of a pymel node as described here:
>>> http://code.google.com/p/pymel/issues/detail?id=62
>>>
>>> allow users to add their own methods to any node. users can now easily 
>>> import pymel and then subclass nodes to do what they like, but perhaps 
>>> there's a way to register these user subclass modules to be loaded by 
>>> pymel, such that they are found within the pymel namespace.
>>>
>>>
>>>
>>> import pymel.core as pm
>>>
>>> # Load plugin
>>> pm.loadPlugin('pointless')
>>>
>>> # Print Node Type
>>> print pm.nt.PointlessViewer
>>>
>>> How would I subclass this and add my own methods?
>>>
>>> class PointlessViewerNode(pm.nt.PointlessViewer):
>>>   def myMethod(self):
>>>       # Do something with my node
>>>       pass
>>>
>>> Do I have to follow the example under pymel.examples.customClasses.py?  
>>> Where an extra attribute is added, ie cls._PointlessClassID?  I'm not sure 
>>> I need this extra attribute, I just want to add additional methods to the 
>>> existing pymel node returned when creating nodes.
>>>
>>> viewer = pm.createNode('pointlessViewer')
>>> viewer.myMethod()
>>>
>>>
>>> Thanks,
>>> Justin
>>>
>>>
>>>
>>>
>>> --
>>> view archives: http://groups.google.com/group/python_inside_maya
>>> change your subscription settings: 
>>> http://groups.google.com/group/python_inside_maya/subscribe
>>
>> --
>> view archives: http://groups.google.com/group/python_inside_maya
>> change your subscription settings: 
>> http://groups.google.com/group/python_inside_maya/subscribe
>
>

-- 
view archives: http://groups.google.com/group/python_inside_maya
change your subscription settings: 
http://groups.google.com/group/python_inside_maya/subscribe

Reply via email to