Refactor extrusion process to use Solidify Modifier for improved thickness control
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -56,24 +56,29 @@ if bpy.context.selected_objects:
|
||||
print(f"Resizing: {current_width:.2f}mm -> {target_width_mm:.2f}mm (Factor: {scale_factor:.4f})")
|
||||
|
||||
# Apply Scale to X and Y (Maintain Aspect Ratio)
|
||||
# We do NOT scale Z because Z is 0 (flat mesh)
|
||||
obj.scale[0] = scale_factor
|
||||
obj.scale[1] = scale_factor
|
||||
|
||||
# Freeze the scale transformation so dimensions are real
|
||||
# Freeze the scale transformation so dimensions are real before adding modifiers
|
||||
bpy.ops.object.transform_apply(location=False, rotation=False, scale=True)
|
||||
else:
|
||||
print("Warning: Object has 0 width, skipping resize.")
|
||||
|
||||
# 3. Extrude (Z-Height)
|
||||
# Now that X/Y are sized correctly, we extrude Z
|
||||
bpy.ops.object.mode_set(mode='EDIT')
|
||||
bpy.ops.mesh.select_all(action='SELECT')
|
||||
# 3. Add Solidify Modifier (Replaces manual extrusion)
|
||||
print(f"Applying Solidify Modifier: Thickness {thickness_mm}mm")
|
||||
|
||||
# Extrude exactly the thickness value
|
||||
bpy.ops.mesh.extrude_region_move(TRANSFORM_OT_translate={"value":(0, 0, thickness_mm)})
|
||||
|
||||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
# Add the modifier
|
||||
mod = obj.modifiers.new(name='PCBSolidify', type='SOLIDIFY')
|
||||
|
||||
# Set Modifier Properties
|
||||
mod.thickness = thickness_mm
|
||||
mod.use_even_offset = True # "Even Thickness: yes"
|
||||
mod.use_rim = True # "Fill Rim: ON"
|
||||
mod.offset = 0 # 0 centers the thickness, 1 extends vertically.
|
||||
# Use 0 or 1 depending on where you want the origin.
|
||||
|
||||
# Apply the modifier (Bake it into the mesh)
|
||||
bpy.ops.object.modifier_apply(modifier=mod.name)
|
||||
|
||||
# --- Step 4: Export STL ---
|
||||
print(f"Exporting to: {output_stl}")
|
||||
|
||||
Reference in New Issue
Block a user