Skip to content

Instantly share code, notes, and snippets.

@Piyush3dB
Last active May 3, 2019 04:16
Show Gist options
  • Save Piyush3dB/852de24a316982f56c161fcce2a63c68 to your computer and use it in GitHub Desktop.
Save Piyush3dB/852de24a316982f56c161fcce2a63c68 to your computer and use it in GitHub Desktop.
import bpy
class Robot(object):
def __init__(self):
pass
def addBody(self, value=(0, 0, 0)):
#body
bpy.ops.mesh.primitive_cube_add()
bpy.ops.transform.resize(value=value)
def addHead(self, value=(0, 0, 0)):
#head
bpy.ops.mesh.primitive_monkey_add()
bpy.ops.transform.translate(value=(value))
def addArm(self, trVal=(0, 0, 0), rsVal=(0, 0, 0), rotVal=0):
#arms
bpy.ops.mesh.primitive_cylinder_add()
bpy.ops.transform.translate(value=trVal)
bpy.ops.transform.resize(value=rsVal)
bpy.ops.transform.rotate(value=rotVal, axis=(0, 1, 0))
def addLeg(self, trVal=(0, 0, 0), rsVal=(0, 0, 0)):
#legs
bpy.ops.mesh.primitive_cylinder_add()
bpy.ops.transform.translate(value=trVal)
bpy.ops.transform.resize(value=rsVal)
# Clear screen
bpy.ops.object.select_all(action='TOGGLE')
bpy.ops.object.select_all(action='TOGGLE')
bpy.ops.object.delete(use_global=False)
# Create Robot
robj = Robot()
robj.addBody(value=(1.2, 0.8, 1.5))
robj.addHead(value=(0, -0.3, 2))
robj.addArm(trVal=( 2, 0, 0), rsVal=(0.5, 0.5, 1.5), rotVal=-0.523599)
robj.addArm(trVal=(-2, 0, 0), rsVal=(0.5, 0.5, 1.5), rotVal=+0.523599)
robj.addLeg(trVal=( 0.7, 0, -3.5), rsVal=(0.5, 0.5, 2))
robj.addLeg(trVal=(-0.7, 0, -3.5), rsVal=(0.5, 0.5, 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment