David Stripinis's book "The MEL Companion" has a whole section on writing a script to create a geosphere. Worth checking out.