44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
import bpy
|
||
import os
|
||
|
||
def cleanup():
|
||
# 删除所有meshes,这样我们可以从一个干净的环境开始
|
||
bpy.ops.object.select_all(action='DESELECT')
|
||
bpy.ops.object.select_by_type(type='MESH')
|
||
bpy.ops.object.delete()
|
||
|
||
def add_thickness_to_stl(input_file_path, output_file_path, thickness=0.1):
|
||
cleanup()
|
||
|
||
# 激活STL导入插件
|
||
bpy.ops.preferences.addon_enable(module="io_mesh_stl")
|
||
|
||
# 导入STL
|
||
bpy.ops.import_mesh.stl(filepath=input_file_path)
|
||
|
||
# 确保导入的模型是当前活跃的
|
||
obj = bpy.context.selected_objects[0]
|
||
bpy.context.view_layer.objects.active = obj
|
||
|
||
# 进入编辑模式
|
||
bpy.ops.object.editmode_toggle()
|
||
|
||
# 选择所有顶点
|
||
bpy.ops.mesh.select_all(action='SELECT')
|
||
|
||
# 使用Solidify修饰器来增加壁厚
|
||
bpy.ops.object.modifier_add(type='SOLIDIFY')
|
||
solidify = obj.modifiers["Solidify"]
|
||
solidify.thickness = thickness
|
||
|
||
# 应用修饰器
|
||
bpy.ops.object.modifier_apply({"object": obj}, modifier="Solidify")
|
||
|
||
# 返回对象模式
|
||
bpy.ops.object.editmode_toggle()
|
||
|
||
# 导出为STL
|
||
bpy.ops.export_mesh.stl(filepath=output_file_path)
|
||
|
||
cleanup()
|