[Tutor] sorting objects with embedded data

Daniel Yoo dyoo@hkn.EECS.Berkeley.EDU
Tue, 15 Aug 2000 12:27:54 -0700 (PDT)


On Tue, 15 Aug 2000 michaelbaker@operamail.com wrote:

> I'm using python with blender (http://www.blender.nl) - an amazing freeware
> 3d modeling and animation package. I'm trying to sort a bunch of objects
> based on their positions in the Z axis direction. 

An easy way to do this is to tell the sort() specifically how to compare
two items based on LocZ.  sort() can take in an optional parameter that
allows you to redefine the sorting order.  Here's a sample comparison
function:

###
def cmpLocZ(cube1, cube2):
    return cmp(cube1.LocZ, cube2.LocZ)
###

Once you have something like this, you can pass this off to the sorting
routine.

###
buffer.sort(cmpLocZ)
###

and things should work well.