Skip to content

Instantly share code, notes, and snippets.

@Piyush3dB
Created May 3, 2019 17:21
Show Gist options
  • Save Piyush3dB/0861dc873368a23dc957d75d84f003a5 to your computer and use it in GitHub Desktop.
Save Piyush3dB/0861dc873368a23dc957d75d84f003a5 to your computer and use it in GitHub Desktop.
import bpy
from random import randint
class Monkey(object):
def __init__(self, location=(0,0,0)):
self.location = location
def add(self):
bpy.ops.mesh.primitive_monkey_add(location=self.location)
def modify(self, type='SUBSURF'):
bpy.ops.object.modifier_add(type=type)
#bpy.context.object.modifiers['Subdivision'].render_levels = 3
#bpy.context.object.modifiers['Subdivision'].levels = 3
bpy.ops.object.shade_smooth()
class Scene(object):
def __init__(self, number):
self.objs = []
self.number = number
def clear(self):
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(use_global=False)
def generate(self):
for i in range(0,self.number):
x = randint(-3, 3)
y = randint(-3, 3)
z = randint(-3, 3)
mkObj = Monkey(location=(x, y, z))
mkObj.add()
mkObj.modify()
# Cear Scene
scene = Scene(10)
scene.clear()
scene.generate()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment