My node compute Does not work properly


#1

hi! My node only works when it’s attributes are displayed in attribute editor or channel Box window!!!
How to fix this problem??
For example:

in this node, I want the compute def to run when my shape that is connected to my node, is moved… but this example is true when showing my node attribute in attribute editor window

Excuse me,I don’t speak English as well as you :confused:


#2

Hi.

In most plugins it is common practice to check if an output plug is dirty or not.

Add an output plug attribute to your node, and inside your compute function, check if the plug is being requested:

    # output ( whatever )
    self.outMeshAttr = typedAttr.create("outMesh", "in", OpenMaya.MFnData.kMesh)
    typedAttr.writable = True
    typedAttr.readable = False
    typedAttr.storable = False
    typedAttr.hidden = False
         
    self.addAttribute(self.aaaAttr) 
    self.addAttribute(self.tttAttr) 
    self.addAttribute(self.inMeshAttr)
    self.addAttribute(self.outMeshAttr)

    # add link (You want the inputs affecting the outputs)
    self.attributeAffects(self.aaaAttr, self.outMeshAttr)
    self.attributeAffects(self.inMeshAttr, self.outMeshAttr)

Next we want to check if that output is requested:
This:

def compute(self, plug, data):
aaaData = data.inputValue(self.aaaAttr)
aaa = aaaData.asFloat()
print “attribute editor or channelBox, show!!”
data.setClean(plug)
return

Should look something like this:

def compute(self, plug, data):
if plug==self.outMeshAttr:
aaaData = data.inputValue(self.aaaAttr)
aaa = aaaData.asFloat()
print “attribute editor or channelBox, show!!”
data.setClean(plug)
return

Now when your output is connected, it should fire off when requesting the plug be updated.

Hope that helps a bit.