Created
February 14, 2016 18:31
-
-
Save scott-wilson/f48bf5792c80c7820ddd to your computer and use it in GitHub Desktop.
Example for abstracting away code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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