<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">'''

combine.py

Inputs: inner.stl, outer.stl
Outputs: inner_capped.stl, outer_capped.stl, combined.stl

 Takes two surfaces (inner and outer)
 Caps the ends
 Cuts the outer object with inner
 Saves it all

Requires Blender, https://www.blender.org/

Run as 'blender -b -P combine.py'

Written by Ahmet Erdemir, erdemira@ccf.org 2017

'''

import bpy

# Read inner object
bpy.ops.object.delete()
bpy.ops.import_mesh.stl(filepath='inner.stl')
# Assign active object to a variable 
Inner = bpy.context.scene.objects.active
# Cap the ends of inner object
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.fill_holes(sides=1000)
bpy.ops.object.mode_set(mode='OBJECT')
# Save inner object with capped ends
bpy.ops.export_mesh.stl(filepath='inner_capped.stl')

# Read outer object
bpy.ops.import_mesh.stl(filepath='outer.stl')
# Assign active object to a variable 
Outer = bpy.context.scene.objects.active
# Cap the ends of outer object
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.fill_holes(sides=1000)
bpy.ops.object.mode_set(mode='OBJECT')
# Save outer object with capped ends
bpy.ops.export_mesh.stl(filepath='outer_capped.stl')


bool1 = Outer.modifiers.new(type='BOOLEAN', name='Boolean 1')
bool1.object = Inner
bool1.operation = 'DIFFERENCE'
bool1.solver='CARVE'

bpy.ops.object.modifier_apply(apply_as='DATA', modifier='Boolean 1')

bpy.data.objects['Inner'].select = True
bpy.data.objects['Outer'].select = False
bpy.ops.object.delete()

bpy.ops.export_mesh.stl(filepath='combined.stl')


</pre></body></html>