Skip to content

Instantly share code, notes, and snippets.

@nezuppo
Created March 12, 2019 14:55
Show Gist options
  • Save nezuppo/81206dff062c0d37a96dcc8324bee29b to your computer and use it in GitHub Desktop.
Save nezuppo/81206dff062c0d37a96dcc8324bee29b to your computer and use it in GitHub Desktop.
blender で切り抜き
import bpy
# まずは全て削除
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(True)
# キューブを作成
bpy.ops.mesh.primitive_cube_add(location=(0, 0, 0))
cube_object = bpy.context.object
cube_object.dimensions = (5, 5, 1)
# 切り抜き用のシリンダー作成
bpy.ops.mesh.primitive_cylinder_add(vertices=100, radius=2, depth=2,
location=(0, 0, 0))
cylinder_object = bpy.context.object
# キューブからシリンダーを抜く
bpy.context.scene.objects.active = cube_object
boolean = cube_object.modifiers.new('cube-boolean', 'BOOLEAN')
boolean.operation = 'DIFFERENCE'
boolean.object = cylinder_object
bpy.ops.object.modifier_apply(modifier='cube-boolean')
# 切り抜いた後の不要になったシリンダー削除
bpy.context.scene.objects.unlink(cylinder_object)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment