Hi All,
I am using the python api (v1) deriving from an MPxNode for a fairly simple plugin.
At the moment I am having trouble figuring out how to retrieve the name/object itself for incoming connections to an MFnMessage Attribute. These are also within an array of MFnCompoundAttributes…
eg.
CompoundArray
- Compound Attribute
- MessageAttribute
- MessageAttribute
In this case, my messageattributes will be connected to a bunch of shadingEngines.message,
At the moment Im just trying to query what that shadingEngine connection is, and afterwards what elements are in the set.
Where im at is below.
class acMaterialSwitch(OpenMayaMPx.MPxNode):
class variables
SwitchAttr = OpenMaya.MObject()
sgData = OpenMaya.MObject()
proxyData = OpenMaya.MObject()
renderData = OpenMaya.MObject()
DummyOut = OpenMaya.MObject()def init(self):
OpenMayaMPx.MPxNode.init(self)
def compute(self,plug,dataBlock):
if plug == acMaterialSwitch.SwitchAttr or plug == acMaterialSwitch.DummyOut: switchVarHandle = OpenMaya.MDataHandle() switchVarHandle = dataBlock.inputValue(acMaterialSwitch.SwitchAttr) switchHandle = switchVarHandle.asShort() #Array of CompoundAttrs to Iterate Over sgDataArray = dataBlock.inputArrayValue (acMaterialSwitch.sgData) noChildren = sgDataArray.elementCount() if noChildren < 1: dataBlock.setClean(plug) return for i in range(noChildren): sgDataArray.jumpToElement(i) #Compound Attr, should be a pair of MsgAttribute sgPairDataHandle = sgDataArray.inputValue() #Handles for each attr in the compound proxyDataHandle = OpenMaya.MDataHandle(sgPairDataHandle.child(acMaterialSwitch.proxyData)) renderDataHandle = OpenMaya.MDataHandle(sgPairDataHandle.child(acMaterialSwitch.renderData)) print proxyDataHandle print renderDataHandle dataBlock.setClean(plug)
def nodeInitializer():
enumAttr= OpenMaya.MFnEnumAttribute()
dummyEnum = OpenMaya.MFnEnumAttribute()
gAttr = OpenMaya.MFnMessageAttribute()
cAttr = OpenMaya.MFnCompoundAttribute()acMaterialSwitch.proxyData = gAttr.create(“proxyData”, “proxyData”)
acMaterialSwitch.renderData = gAttr.create(“renderData”, “renderData”)
gAttr.setReadable(1)
gAttr.setWritable(1)
gAttr.setConnectable(1)
gAttr.setHidden(0)
ProxyAttr = gAttr.create(“PROXY”, “PROXY”)
acMaterialSwitch.sgData = cAttr.create(“sgData”, “sgData”)
cAttr.setArray(1)
cAttr.setHidden(0)
cAttr.setUsesArrayDataBuilder(1)
cAttr.addChild(acMaterialSwitch.proxyData)
cAttr.addChild(acMaterialSwitch.renderData)Grps = [“PROXY”, “RENDER”]
acMaterialSwitch.SwitchAttr = enumAttr.create(“Switch”, “Switch”, 0)
acMaterialSwitch.DummyOut = dummyEnum.create(“Dummy”, “Dummy”, 0)for g in Grps:
attrF = enumAttr.addField(g, Grps.index(g))
attrD = dummyEnum.addField(g, Grps.index(g))
acMaterialSwitch.addAttribute(acMaterialSwitch.SwitchAttr)
acMaterialSwitch.addAttribute(acMaterialSwitch.DummyOut)acMaterialSwitch.addAttribute(acMaterialSwitch.sgData)
enumAttr.setReadable(1)
enumAttr.setStorable(1)
enumAttr.setHidden(0)#dummyEnum.setHidden(1)
acMaterialSwitch.attributeAffects(acMaterialSwitch.SwitchAttr, acMaterialSwitch.DummyOut)
acMaterialSwitch.attributeAffects(acMaterialSwitch.sgData, acMaterialSwitch.DummyOut)
Any assistance would be great, as i am feeling a little lost in this at the moment and havent been able to retrieve many ( if any ) practical examples of MFnMessage being used.