Macro Cut Object For Magnets

Macro Cut Object for Magnets

Description
Cut an object along a plane and add aligned magnet holes with surface collision detection. Creates two parts with perfectly aligned holes for embedding magnets that allow the parts to snap together.

Macro version: 0.6.2
Last modified: 2026-01-18
FreeCAD version: 0.21+
Download: ToolBar Icon
Author: Spkane
Author
Spkane
Download
ToolBar Icon
Links
Macro Version
0.6.2
Date last modified
2026-01-18
FreeCAD Version(s)
0.21+
Default shortcut
None
See also
Part Slice, PartDesign Hole

Description

This macro cuts a 3D object along a specified plane and automatically adds aligned magnet holes to both resulting pieces. The holes are positioned with intelligent collision detection to ensure they don't break through the outer walls of the object.

This is particularly useful for:

Key Features:

Usage

  1. Open a document with the object you want to cut.
  2. Optionally select the object and/or a datum plane before running the macro.
  3. Run the macro from Macro → Macros → CutObjectForMagnets → Execute.
  4. In the dialog:
    • Select the body to cut from the dropdown.
    • Choose the cut plane type (Preset or Model Plane).
    • For preset planes, set the offset from origin.
    • Configure magnet hole parameters:
      • Diameter: Hole diameter (should match your magnet size).
      • Depth: Hole depth from cut surface.
      • Number of Holes: Total holes to create.
      • Edge Clearance (Preferred): Ideal distance from hole edge to object surface.
      • Edge Clearance (Minimum): Minimum acceptable clearance.
  5. Click "Execute Cut".

Example

This image shows a vase object in its original form, and after being cut multiple times with the macro. Magnets can then be inserted into the object, and the object can be re-assembled. This example was to create a "breakable" vase for a theatrical stage performance, but there are many other potential uses as well.

How It Works

Cutting Process:

  1. Creates a large half-space box aligned with the cutting plane.
  2. Uses boolean operations to split the object into two parts.
  3. Creates PartDesign::Body containers for each half.

Hole Placement Algorithm:

  1. Calculates hole positions evenly distributed along the cut face perimeter.
  2. For each position, validates against BOTH parts (not just one).
  3. Uses preferred clearance first, falls back to minimum if needed.
  4. Checks for hole-to-hole spacing (minimum 2x diameter).
  5. Repositions holes that fail safety checks using multiple strategies:
    • Reduced clearance at same position.
    • Increased inset from edge.
    • Alternative positions along the perimeter.

Safety Features:

Parameters

Parameter Description Default
Plane Type "Preset Plane" (XY/XZ/YZ) or "Model Plane" (datum plane) Preset Plane
Offset Distance from origin for preset planes 0 mm
Diameter Magnet hole diameter 3 mm
Depth Hole depth from cut surface 3 mm
Number of Holes Total holes to create 6
Edge Clearance (Preferred) Ideal distance from hole edge to object surface 2 mm
Edge Clearance (Minimum) Minimum acceptable clearance (used during repositioning) 0.5 mm

Requirements

Installation

Tips

Source Code

The full source code is hosted on GitHub:

Links