Ah, I see what you meant now... sorry. I think I forgot myself how the
virtual node creation process worked... =/

Anyway, yes, you're right 'newNode' will not yet be an instance of your new
virtual class.  However, you can still call methods of your new class -
just pass in the node explicitly:

MyVirtualClass.myMethod(newNode, arg1, ...)

However... the *Create stuff are only used when the actual maya node is
created in the scene - and even then, only when created by using a PyNode -
ie, MyVirtualClass(name='foo').  If you want to run something everytime an
instance is created, like a normal __init__... you should still be able to
just override __init__.  Just make sure that you make it accept *args and
**kwargs (because you shouldn't make any assumptions about what the
incoming args/kwargs will be), and make sure you call the super __init__.

- Paul

On Fri, Oct 19, 2012 at 2:03 PM, Morgan <[email protected]> wrote:

> Right, all the pymel methods are available, but in that example, if I add
> a method to CustomJointBase called customMethod and then try to call that
> within _postCreateVirtual like so:
>
> newNode.customMethod()
>
> I get an error because I newNode isn't an instance of my new virtual class:
> # AttributeError: nt.Joint(u'leftLeg') has no attribute or method named
> 'customMethod' #
>
> I can call it just fine once the class has been instanced in another
> function or script, just not within the node creation methods of the class
> itself. Is that right?
>
>
> On Saturday, October 20, 2012 8:19:33 AM UTC+13, elrond79 wrote:
>
>> Nope, it's an instance of the class, and you can use it exactly as you
>> would self.  Check the example file at:
>>
>> https://github.com/**LumaPictures/pymel/blob/**
>> master/examples/customClasses.**py<https://github.com/LumaPictures/pymel/blob/master/examples/customClasses.py>
>>
>> In it's _postCreateVirtual, it adds an attribute, and calls it's .attr
>> method...
>>
>> - Paul
>>
>>
>> On Fri, Oct 19, 2012 at 12:13 PM, Morgan <[email protected]> wrote:
>>
>>> But that new node is different from self because it's just a node, not
>>> an instance of the class, so although you can act on the node directly, you
>>> can't call any of the custom methods or set member variables, I don't
>>> think....
>>>
>>>
>>> On Saturday, October 20, 2012 7:33:39 AM UTC+13, elrond79 wrote:
>>>>
>>>> Morgan - though _postCreateVirtual is indeed a classmethod, when it is
>>>> called by pymel's mechanics, it is always passed in the "newNode" as the
>>>> first argument (after the classmethod-automatically-**crea**ted 'cls'
>>>> arg, of course).  So you can use this arg just as you would "self" in a
>>>> "normal" instance method.
>>>>
>>>> - Paul
>>>>
>>>  --
>>> view archives: 
>>> http://groups.google.com/**group/python_inside_maya<http://groups.google.com/group/python_inside_maya>
>>> change your subscription settings: http://groups.google.com/**
>>> group/python_inside_maya/**subscribe<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