On Thu, Sep 25, 2008 at 7:16 AM, Mario Dubec <[EMAIL PROTECTED]> wrote:
> Ok, i will try that if statement at the beginning.
>
> It crashes either:
> 1. when i plug anything into it, correct or incorrect does not matter
> 2. when I have plugin loaded and try to create new scene in current Maya
> session

No, I meant at what point in your compute() method does it crash. You
have a print statement at each stage. What's the last one to be
displayed before it crashes?

> By moving it to connection methods, should I call them at the beginning of
> compute? Or return some status from them? (like unknown parameter) Never
> used those :( I am quite new to API :(

You don't need to call the connection methods at all. Maya will call
them whenever a connection is made to your node or broken. So you'd
want something like this:

        import maya.OpenMaya as om
        import maya.OpenMayaFX as omfx

        class myNode(om.MPxNode):
                particleNode = om.MObject()             # to hold particleNode 
attr
                fluidNode = om.MObject()                # to hold fluidNode attr
                debugMe = om.MObject()                  # to hold debugMe attr

                def __init__(self):
                        self.particleNodeValid = False
                        self.fluidNodeValid = False
                        ompx.MPxNode.__init__(self)

                def connectionMade(self, myPlug, otherPlug, iAmSrc):
                        if not iAmSrc:
                                if myPlug == myNode.particleNode:
                                        otherNode = otherPlug.node()

                                        # If the connection is to a particle 
node, mark it valid.
                                        if otherNode.hasFn(om.MFn.kParticle):
                                                self.particleNodeIsValid = True
                                                self.particleNodeFn = 
omfx.MFnParticleSystem(otherNode)
                                        else:
                                                self.particleNodeIsValid = False
                                                self.particleNodeFn = None

                                elif myPlug == myNode.fluidNode:
                                        otherNode = otherPlug.node()

                                        # If the connection is to a fluid node, 
mark it valid.
                                        if otherNode.hasFn(om.MFn.kFluid):
                                                self.fluidNodeIsValid = True
                                                self.fluidNodeFn = 
omfx.MFnFluid(otherNode)
                                        else:
                                                self.fluidNodeIsValid = False
                                                self.fluidNodeFn = None

                def connectionBroken(self, myPlug, otherPlug, iWasSrc):
                        if not iWasSrc:
                                if myPlug == myNode.particleNode:
                                        self.particleNodeIsValid = False
                                        self.particleNodeFn = None
                                elif myPlug == myNode.fluidNode:
                                        self.fluidNodeIsValid = False
                                        self.fluidNodeFn = None

                def compute(self, plug, block):
                        if plug == myNode.debugMe:
                                if self.particleNodeIsValid and 
self.fluidNodeIsValid:
                                        result = "both connected"
                                elif self.particleNodeIsValid:
                                        result = "particle connected"
                                elif self.fluidNodeIsValid:
                                        result = "fluid connected"
                                else
                                        result = "neither connected"

                                
block.outputValue(myNode.debugMe).setString(result)
                                return om.MStatus.kSuccess

                        # This is not an attribute that I recognize, so let 
Maya know that
it should handle it.
                        return om.MStatus.kUnknownParameter

So you use connectionMade and connectionBroken to maintain a pair of
flags indicating which connections are currently valid. I've also got
them creating the corresponding function sets so that they'll be ready
for compute() to use when its needs them. If you find that it's still
crashing then try having compute() create the functionsets for itself.

The compute() simply checks the flags to see what's valid and takes
action based on that.

-- 
-deane

--~--~---------~--~----~------------~-------~--~----~
Yours,
Maya-Python Club Team.
-~----------~----~----~----~------~----~------~--~---

Reply via email to