How to correctly handle the result of a Boolean modifier?

Hello everyone.

I have a problem of understanding.

  1. Load 2 stl files (object1 is a cube, object2 e.g. a torus)
  2. Apply boolean modifier on it
  3. Save intersection as stl (part of object2 that lies within cube)
  4. Remove all objects
  5. Load stl from step 3 to work further with it

I assume that I don’t have to save the intersection and load it again. How is this done correctly?

stl_filepath_1 = sys.argv[-2]
stl_filepath_2 = sys.argv[-1]

bpy.ops.import_mesh.stl(filepath=stl_filepath_1)
obj1 = bpy.context.selected_objects[0]
bpy.ops.import_mesh.stl(filepath=stl_filepath_2)
obj2 = bpy.context.selected_objects[0]

boolean_mod = obj1.modifiers.new(name="Boolean", type='BOOLEAN')
boolean_mod.operation = 'INTERSECT'
boolean_mod.use_self = False
boolean_mod.object = obj2

bpy.ops.object.modifier_apply(modifier=boolean_mod.name)

bpy.ops.object.select_all(action='DESELECT')
obj1.select_set(True)

bpy.ops.export_mesh.stl(filepath='temp.stl', use_selection=True)

bpy.ops.object.select_all(action='DESELECT')
bpy.ops.object.select_by_type(type='MESH')
bpy.ops.object.delete()

bpy.ops.import_mesh.stl(filepath='temp.stl')

hey,

still in need? i must say i don’t understand your question, what is wrong?