monsteradurm
Hi All,

Im having some trouble figuring out how to return the nodes connected to my MFnCompoundAttribute.

In this case the compound has two child attributes, both of MFnMessageAttribute type.

This is where im getting super confused.. I understand how to iterate over all of the individual elements in the compoundattribute array, but not how to then get the objects connected to those..

any assistance or guidance would be awesome..

here is where i am in the compute function..

Code:

def compute(self,plug,dataBlock):
    
    if plug == acMaterialSwitch.SwitchAttr or plug == acMaterialSwitch.DummyOut:
      switchVarHandle = OpenMaya.MDataHandle()
      switchVarHandle = dataBlock.inputValue(acMaterialSwitch.SwitchAttr)
      switchHandle = switchVarHandle.asShort()
            
      sgDataArray = dataBlock.inputArrayValue (acMaterialSwitch.sgData)
      
      noChildren = sgDataArray.elementCount()
      
      if noChildren < 1:
          dataBlock.setClean(plug)
          return
      
      #sgSwitchPair = sgDataArray.
      for i in range(sgDataArray.elementCount() - 1):
        sgDataArray.next()
                
        DataHandle = OpenMaya.MDataHandle()
        DataHandle = sgDataArray.inputValue()
        print DataHandle.type()
                print DataHandle.asString()
        
    dataBlock.setClean(plug)
Quote 0 0
monsteradurm
Was burning the midnight oil a bit too much last night when I posted this so i realise now there probably wasnt even enough clarity in what i had written.

To clarify ( and hopefully communicate what I am doing a bit better ) my data structure should be set up like this

Array of compound Attributes with each compound attribute having a pair of messageAttributes.

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, which at the moment returns an internal failure each time ( when the compute method is run, I can connect everything fine).

Code:

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.MArrayDataHandle(sgPairDataHandle.child(acMaterialSwitch.proxyData))
        renderDataHandle = OpenMaya.MArrayDataHandle(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)


Quote 0 0
pshipkov
Code:

MArrayDataHandle adh = data.inputArrayValue (sgData);
unsigned int c = adh.elementCount();
for(unsigned int i = 0; i < c; ++i)
{
    adh.jumpToArrayElement(i);
    MDataHandle dhProxyData = adh.inputValue().child(proxyData);
    MDataHandle dhRenderData = adh.inputValue().child(renderData);
}
Quote 0 0

Add a Website Forum to your website.