Thanks, Dean...but I used this ccecking in compute while I was translating one C++ node from devkit (particleAttributeNode I think).
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) while I have set the attribute relationship as: attributeAffects(node.enableDensity, node.debugMe) #enable density is always on I am trying to construct this node in parts while constantly debugging (if I would just run the shole compute, which will be large, it would be hard to identify errors) So basically the compute method goes thru itself and sets node's attribute debugMe to appropriate value based on the computation stage 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 :( 2008/9/25 Dean Edmonds <[EMAIL PROTECTED]> > > On Thu, Sep 25, 2008 at 12:51 AM, MaxtorAG <[EMAIL PROTECTED]> wrote: > > > > Problem: > > 1. I did not know how to construct the MPlug with function (MObject, > > Attribute) (there is no thisObject() function in python API?) > > 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 > > > > --~--~---------~--~----~------------~-------~--~----~ Yours, Maya-Python Club Team. -~----------~----~----~----~------~----~------~--~---
