I’ve finally updated my demo reel! It has my new smooth stretch algorithm front and center. If you didn’t quite understand some of the concepts of my previous posts, you should definitely look at the video. I think it makes the concept if not the math a lot easier to understand.

I also wanted to share this short method I made for accessing OpenMaya array attributes. It’s very quick and simple. I’d rather encapsulate things like this into smaller functions since the API has so many non-standard elements. Remembering them all can be a hassle.

def getSparseArray(data, attr, asType):
	''' Get the values from an array attribute using the datablock.
	Returns a dictionary with the indexes as keys.

	asType should be the function to convert the value to the proper type,
	e.g. om.MDataHandle.asMatrix()'''
	arrayHandle = data.inputArrayValue( attr )
	items = {}
	for i in range(arrayHandle.elementCount()):
		items[arrayHandle.elementIndex()] = asType(arrayHandle.inputValue())
	return items

If it isn’t immediately clear how you would use this, for a matrix array attribute that was created in the initialize method like this:

def nodeInit(self):
	matrixAttr = om.MFnMatrixAttribute()

	# Inputs
	self.aParentInverseMatrices = matrixAttr.create('parentInverseMatrix', 'parentInverseMatrix', om.MFnMatrixAttribute.kDouble)

	self.addAttribute( self.aParentInverseMatrices )

I would call my sparse method in the compute method like so:

def compute (self, plug, data):
	inverseMatrices = getSparseArray(data, self.aParentInverseMatrices, om.MDataHandle.asMatrix)

I just wrote this a few hours ago, and I can’t tell you how happy it made me. Now I don’t need to think nearly as hard when accessing sparse array attributes from the datablock. Of course, this still doesn’t help for all the other ways you might need to access array attributes. Getting the output value, or using the physical index, or getting it from a plug, or getting it from the other type of array attributes. Good God, this stuff needs to be simplified! In any case, good luck and god speed if you’re trying to use the Maya API to do anything.