-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathintersect.py
More file actions
28 lines (21 loc) · 787 Bytes
/
intersect.py
File metadata and controls
28 lines (21 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import bpy
import sys
index = sys.argv.index("--")
file_a = sys.argv[index + 1]
file_b = sys.argv[index + 2]
file_out = sys.argv[index + 3]
bpy.ops.object.select_all(action = 'SELECT')
bpy.ops.object.delete()
bpy.ops.import_mesh.stl(filepath = file_a)
obj_a = bpy.context.selected_objects[0]
bpy.ops.import_mesh.stl(filepath = file_b)
obj_b = bpy.context.selected_objects[0]
bpy.context.view_layer.objects.active = obj_a
bpy.ops.object.modifier_add(type = 'BOOLEAN')
bpy.context.object.modifiers[0].object = obj_b
bpy.context.object.modifiers[0].operation = 'INTERSECT'
bpy.ops.object.modifier_apply(modifier='Boolean')
bpy.context.view_layer.objects.active = obj_b
bpy.ops.object.delete()
bpy.context.view_layer.objects.active = obj_a
bpy.ops.export_mesh.stl(filepath = file_out)