Hello,

I'm working on a surface shader plugin and have run into problems when the 
attributes of the plugin are keyframed and the plugin is queried in a loop 
that calls cmds.currentTime to change frames, as might happen during a bake 
or a batch render. Has anyone seen something like this before? 

The attached plugin and scenes are as boiled down as I could go. If you run 
the following commands with the v001 scene that has no keyframes, the loop 
runs as expected. If you run the commands in scene v002, where the 
'testMaterial' intensity attribute is keyframed, Maya hangs pretty much 
immediately. Note that the keyframed attribute doesn't have to be queried 
to cause the hang, it just has to be keyframed.

Thanks in advance for your help,
Bob


nodesPath = "/tmp/maya"
cmds.loadPlugin( "%s/testMaterial.py" % nodesPath )

node = "testMaterial1"
value = 0
for i in range(0,10):
    print( i )
    print( "changing frames" )
    cmds.currentTime(float(i))

    #value = cmds.getAttr( "%s.%s" % (node, "intensity") )
    print( i, value )

-- 
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/cb4b9aeb-c0fc-4ca4-b2b1-5e92bedca3a9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Attachment: materialPlugin.tgz
Description: GNU Unix tar archive

import maya.OpenMaya as OpenMaya
import maya.OpenMayaMPx as OpenMayaMPx
 
class testMaterial(OpenMayaMPx.MPxNode):    
    # node attribute setup helper functions
    @staticmethod
    def makeInput(attr):
        attr.setKeyable(1)
        attr.setStorable(1)
        attr.setReadable(1)
        attr.setWritable(1)

    @staticmethod
    def makeFloat(cls,longName, shortName, default = 0.0):
        nAttr = OpenMaya.MFnNumericAttribute()
        attrOut = nAttr.create(longName, shortName, OpenMaya.MFnNumericData.kFloat)
        testMaterial.makeInput( nAttr )
        nAttr.setDefault( default )
        #return attrOut
        cls.addAttribute(attrOut)
        
    @staticmethod
    def makeOutColor(cls):
        # a special color attribute for shading purposes
        nAttr        = OpenMaya.MFnNumericAttribute()
        cls.outColor = nAttr.createColor("outColor", "oc")
        nAttr.setKeyable(0)
        nAttr.setStorable(0)
        nAttr.setReadable(1)
        nAttr.setWritable(0)
        cls.addAttribute(cls.outColor)

    @staticmethod
    def nodeName():
        return "testMaterial"

    @staticmethod
    def nodeId():
        return OpenMaya.MTypeId(0x6C757803) #borrowing lux id area

    @staticmethod
    def nodeType():
        return  OpenMayaMPx.MPxNode.kDependNode

    @staticmethod
    def nodeClassify():
        return "shader/surface"

    def __init__(self):
        OpenMayaMPx.MPxNode.__init__(self)

    @classmethod
    def nodeCreator(cls):
        return OpenMayaMPx.asMPxPtr(cls())
  
    def compute(self, plug, block):
        if plug == self.outColor:            
            resultColor = OpenMaya.MFloatVector(0.5, 0.0, 0.0)
            
            outColorHandle = block.outputValue( self.outColor )
            outColorHandle.setMFloatVector(resultColor)
            outColorHandle.setClean()
        else:
            return OpenMaya.kUnknownParameter

        return None
  
    @classmethod
    def nodeInitializer(cls):
        cls.makeOutColor(cls)
        cls.makeFloat(cls,'intensity','in',1.0)
        
def initializePlugin(mobject):
        mplugin = OpenMayaMPx.MFnPlugin(mobject)
        try:
                mplugin.registerNode( testMaterial.nodeName(), 
                    testMaterial.nodeId(), 
                    testMaterial.nodeCreator, 
                    testMaterial.nodeInitializer, 
                    testMaterial.nodeType(), 
                    testMaterial.nodeClassify() )
        except:
                sys.stderr.write( "Failed to register node: %s" % testMaterial.nodeName() )
                raise

# uninitialize the script plug-in
def uninitializePlugin(mobject):
        mplugin = OpenMayaMPx.MFnPlugin(mobject)
        try:
                mplugin.deregisterNode( testMaterial.nodeId() )
        except:
                sys.stderr.write( "Failed to deregister node: %s" % testMaterial.nodeName() )
                raise      


        

Reply via email to