Sorry, forgot to mention that the script uses an unreleased procedural library, so you can't run it at the moment. Maybe someday. It was meant more as an example of using the MoI programming API rather than something you could try yourself at home...
Michael, if you could just finalise the API Dave used, polish it to a high sheen, add a nice little front end, document the whole thing in detail and release in time the weekend, I'd be grateful.