- 3DBUZZ.com offers A NEW mayaPython DVD ...
http://www.3dbuzz.com/xcart/product.php?productid=54&cat=16&page=1
( i ordered it last week / i can tell you , how it is , when the
shipping arrives - hope they will send it by "plane" - HAHA )
- there is one "Autodesk" DVD "Python for Maya" / it shows how to create
a simple-PYTHON-node ( really basic stuff , and you won't learn much
from it )
http://store.autodesk.com/DRHM/servlet/ControllerServlet?Action=DisplayProductDetailsPage&SiteID=adsk&Locale=en_US&productID=98208500
- i got the Digital-Tutors DVD somewhere , i think there is also a
"tiny" part about scripted-plugins on it . but i do not think , it is so
informative - as it is mainly about python-basics
API:
there are 2 Books
"Complete Maya Programming" by David Gould / you can find them on Amazon
... here you can learn a lot about API ( C++ )
... there is not much python-API-information on the internet yet / but
somehow , you can to try to "translate" the C++ API-tutorials into
Python / python_API is easier to learn than C++ , as you can "source"
the code directly in Maya without compiling it .
Information about maya-API :
http://www.robthebloke.org/mayaapi.html
http://comet-cartoons.com/3ddocs/mayaAPI/
hope that helps you a little , although i can't tell anything about
fluids ...
sim.On
MaxtorAG schrieb:
Use MPxNode::thisMObject().
> 2. When I create the node, everything works. I get the correct integer
> number for my debugging (0 for both). As soon as I connect anything to
> those message atts, I get crash. Even without that, when I after
> creation try to create new scene, I get crash. If I comment out the
> connection checking functions, nothing crashes.
The purpose of a node's compute() method is to compute the value of a
requested output attribute using the values of one or more of the
node's input attributes. Maya will call your node's compute() whenever
it needs the value of one of your node's attributes which may have
changed since it was last retrieved. Note that this is true not just
for attributes which you have added to your node, but also for
standard attributes which Maya provides for every node.
In your compute() you are executing your code every time it is called,
regardless of the attribute whose value is being requested.
Furthermore, your code is not computing anything, by which I mean that
it never sets the datablock values for any output attributes. So Maya
is calling your compute() to get values for various attributes, but
you are not providing any. I'm guessing that that is what is causing
the crash, though there are other possibilities as well.
The code that you have in your compute() just seems to be checking to
be sure that the correct types of nodes are connected to the plugs.
The compute() is not the right place to do that. If you really want to
be sure that only the correct type of node is connected, then provide
an override for the MPxNode::legalConnection() method. Do the check
there and refuse the connection if it is to the wrong node type.
As for the compute() itself, the question you must ask yourself is:
what are the outputs and what are the inputs that you need to compute
each of those outputs?
--
-deane
I would still recommend moving that code out to either the
legalConnection/legalDisconnection methods or
connectionMade/connectionBroken. I doubt that will fix your crash, but
it's a good start to cleaning up the compute().
The particleAttributeNode sample node is doing it the way that it is
because, quite frankly, it's badly written. The author tried to cram
what should be two different nodes into one and ended up with some bad
code as a result.
> What I did not say in the script, but I have, is the final part of the
> computation:
>
> outputHandle = dataBlock.outputValue(node.debugMe)
> outputHandle.setString(result)
> dataBlock.setClean(plug)
In that case you should only be executing your code when the plug
passed to your compute() method is for 'debugMe'. For all others your
compute() method should immediately return
om.MStatus.kUnknownParameter.
> so I was expecting, when nothing is connected, the value would be 0 and
> stage 4
> when I connect appropriate nodes, value would be 1 and stage 4
>
> but I get crash only :(
At which stage does it crash?
--
-deane
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