PDA

View Full Version : computing MFnMatrixAttribute..?


eek
10-06-2011, 02:22 AM
Trying to get the hang of using matrices in the API with Python.

For the initialize method i have something like this:

mAttr = OpenMaya.MFnMatrixAttribute()
nAttr = OpenMaya.MFnNumericAttribute()

plugin.input = mAttr.create('input', 'in')
mAttr.setKeyable(True)
mAttr.setStorable(True)

plugin.output = nAttr.create('output','out', OpenMaya.MFnNumericData.k3Double)

For the compute i have something like this:

inputHandle = dataBlock.inputValue(plugin.input)
outputHandle = dataBlock.outputValue(plugin.output)

result = inputHandle.asMatrix()

outputHandle.set3Double(result(3,0), result(3,1), result(3,2))
datablock.setClean(plug)

Anyone know why this wouldnt work?, i did a simple test plugging in a locators.m (matrix) attribute into the input. And the output to another locators.translate property.

Wondering if i have to specify the attribute type, something like this? eg.

mAttr.create('input', 'in', OpenMaya.MFnMatrixData.kDouble)

Any help is much appreciated

dbsmith
10-06-2011, 04:24 AM
Hmm, at a glance it looks ok to me.

Did you remember to set attributeAffects?
Does your compute() method have a check for the plug type first?
If you print the output values, are you seeing them correctly?

Also, the matrix create should already default to kDouble, so that shouldn't be the problem.

eek
10-06-2011, 04:03 PM
Hmm, at a glance it looks ok to me.

Did you remember to set attributeAffects?
Does your compute() method have a check for the plug type first?
If you print the output values, are you seeing them correctly?

Also, the matrix create should already default to kDouble, so that shouldn't be the problem.

ok cool, so i don't need to specify the attribute type - ill check that it has the attributeAffects, setClean on the plug etc.. Didnt know i could put print into the compute - good idea.

thx

eek
10-07-2011, 01:33 AM
Cool, that was it i needed to add the .attributeAffects - everything working now :)

Thanks,

CGTalk Moderation
10-07-2011, 01:33 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.