Hi everyone,
Has anyone had experience creating a custom assembly reference node in Maya? I’ve poked around a bit in the sceneAssembly devkit solution but haven’t had much success.
Can these be created as a virtual node in Python or will I need to create a custom assembly reference through a plug-in?
Thanks!
Ah, so after some digging and a bit of help I was able to get the missing piece to my custom node creation. I couldn’t find this bit readily available so posting it below!
The magic is in the _createVirtual() method.
import pymel.core as pm
from pymel.internal.factories import virtualClasses
class CustomReference(pm.nt.AssemblyReference):
''' Custom assembly virtual class '''
@classmethod
def _isVirtual(cls, obj, name):
''' Return if node is virtual
Usually determined by a custom attribute or subclassing from a custom node.
'''
return True
@classmethod
def _preCreateVirtual(cls, **kwargs):
return kwargs
@classmethod
def _postCreateVirtual(cls, node, **kwargs):
pass
@classmethod
def _createVirtual(cls, *args, **kwargs):
''' This was the missing piece from my earlier attempts.
This method will actually create the requested node, override this to create an assembly reference.
'''
kwargs['type'] = 'assemblyReference'
node = pm.assembly(*args, **kwargs)
virtualized = pm.PyNode(node)
return node.longName()
def helloWorld(self):
''' Custom method '''
print 'Hello world from a custom assembly!"
virtualClasses.register(CustomReference, nameRequired=False)
myassembly = CustomReference()
myassembly.helloWorld()