Skip to content

Instantly share code, notes, and snippets.

@rezonn
Last active January 9, 2021 12:11
Show Gist options
  • Save rezonn/150e333cd1a1a4199f66c04dd381b203 to your computer and use it in GitHub Desktop.
Save rezonn/150e333cd1a1a4199f66c04dd381b203 to your computer and use it in GitHub Desktop.
blender defs
import bpy
from math import *
def delete(obj):
bpy.ops.object.select_all(action='DESELECT')
obj.select_set(True)
bpy.ops.object.delete()
def box2(w,h,d):
bpy.ops.mesh.primitive_cube_add(size=1)
cybe = bpy.context.object
cybe.scale[0] = w
cybe.scale[1] = h
cybe.scale[2] = d
return cybe
def difference(Obj,obj,dlt=False):
bpy.context.view_layer.objects.active = Obj
modifier = Obj.modifiers.new(name="Boolean2", type='BOOLEAN')
modifier.object = obj
modifier.operation = 'DIFFERENCE'
bpy.ops.object.modifier_apply(modifier="Boolean2")
if dlt > 0 :
delete(obj)
return Obj
def cylinder2(v,d,h):
bpy.ops.mesh.primitive_cylinder_add(vertices=v, radius=d/2, depth=h)
cyl = bpy.context.object
return cyl
def box(w,h,d):
bpy.ops.mesh.primitive_cube_add(size=1)
cybe = bpy.context.object
cybe.scale[0] = w
cybe.scale[1] = h
cybe.scale[2] = d
tempmode = bpy.context.scene.tool_settings.use_transform_data_origin
bpy.context.scene.tool_settings.use_transform_data_origin = True
bpy.ops.transform.translate(value=(-w/2, -h/2, -d/2))
bpy.context.scene.tool_settings.use_transform_data_origin = tempmode
cybe.location = (0, 0, 0)
return cybe
def boxc(w,h,d):
bpy.ops.mesh.primitive_cube_add(size=1)
cybe = bpy.context.object
cybe.scale[0] = w
cybe.scale[1] = h
cybe.scale[2] = d
tempmode = bpy.context.scene.tool_settings.use_transform_data_origin
bpy.context.scene.tool_settings.use_transform_data_origin = True
bpy.ops.transform.translate(value=(-w/2, 0, -d/2))
bpy.context.scene.tool_settings.use_transform_data_origin = tempmode
cybe.location = (0, 0, 0)
return cybe
def cylinder(d,h,v=32):
bpy.ops.mesh.primitive_cylinder_add(vertices=v, radius=d/2, depth=h)
cyl = bpy.context.object
tempmode = bpy.context.scene.tool_settings.use_transform_data_origin
bpy.context.scene.tool_settings.use_transform_data_origin = True
bpy.ops.transform.translate(value=(0, 0, -h/2))
bpy.context.scene.tool_settings.use_transform_data_origin = tempmode
cyl.location = (0, 0, 0)
return cyl
def screwhole():
B = cylinder2(32,10,6)
h = cylinder2(32,4,4)
H = cylinder2(32,8,4)
h.location=(0,0,-2)
H.location=(0,0,2)
d = difference(B,h,True)
d = difference(B,H,True)
return B
side = 8
servo = [40,20,40]
hole = cylinder(32,4.5,servo[2])
temp = box(servo[0],servo[1],servo[2])
left = box(servo[0]+2*side,servo[1]+2*side,side)
hole.location[1] = -9.6/2
left = difference(left,temp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment