Skip to content

Instantly share code, notes, and snippets.

@scott-wilson
Created February 14, 2016 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scott-wilson/f48bf5792c80c7820ddd to your computer and use it in GitHub Desktop.
Save scott-wilson/f48bf5792c80c7820ddd to your computer and use it in GitHub Desktop.
Example for abstracting away code
import random
# An ugly way to get which 3d package you're in.
try:
from maya import cmds
_IN_MAYA = True
except ImportError:
_IN_MAYA = False
try:
import maxAPI
_IN_MAX = True
except ImportError:
_IN_MAX = False
def make_sphere(name, radius, position):
if _IN_MAYA:
# The arguments I'm using are probably wrong. They're just for illustration purposes.
return cmds.polySphere(name=name, radius=radius, position=position)[0]
elif _IN_MAX:
# The Max API is probably completely wrong. Once again, this is to illustrate what I'm doing.
return maxAPI.sphere(name=name, diameter=radius/2, x=position[0], y=position[1], z=position[2])
for i in xrange(1000):
make_sphere("sphere{}".format(i), 1, (random.random()*100, random.random()*100, random.random()*100))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment