Something went wrong. Try again.
a freecad plugin to turn designs into lasercuttable panels
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182"""Run in FreeCAD's Python console, or with a Python that can import FreeCAD.
Writes example source documents and matching DXFs beside this script."""
import mathimport sysfrom pathlib import Pathfrom zipfile import ZipFile
import FreeCAD as Appimport Part
ROOT = Path(__file__).resolve().parents[1]sys.path.insert(0, str(ROOT))
from panel_decomposer.dxf import export_dxffrom panel_decomposer.engine import decomposefrom panel_decomposer.geometry import polygonfrom panel_decomposer.model import Settings
def create_examples(): folder = ROOT / "examples" settings = Settings(labels=False) box = Part.makeBox(80, 60, 40) document = App.newDocument("FingerJointBox") source = document.addObject("Part::Feature", "Box") source.Label = "80 × 60 × 40 box — select all six faces" source.Shape = box document.recompute() document.saveAs(str(folder / "finger-joint-box.FCStd")) export_dxf(decompose(box, range(1, 7), settings), folder / "finger-joint-box.dxf") App.closeDocument(document.Name)
hexagon = polygon([App.Vector(60 * math.cos(i * math.pi / 3), 60 * math.sin(i * math.pi / 3), 0) for i in range(6)]).extrude(App.Vector(0, 0, 40)) document = App.newDocument("AngledFingerJointBox") source = document.addObject("Part::Feature", "HexagonalBox") source.Label = "Hexagonal box — 120° corners, 40 mm tall — select all eight faces" source.Shape = hexagon document.recompute() document.saveAs(str(folder / "angled-finger-joint-box.FCStd")) export_dxf(decompose(hexagon, range(1, len(hexagon.Faces) + 1), settings), folder / "angled-finger-joint-box.dxf") App.closeDocument(document.Name)
edge = next(edge for edge in box.Edges if abs(edge.tangentAt(edge.FirstParameter).z) > 0.9 and edge.Vertexes[0].Point.x > 79 and edge.Vertexes[0].Point.y > 59) rounded = box.makeFillet(8, [edge]) index, fillet = next((i, face) for i, face in enumerate(rounded.Faces, 1) if isinstance(face.Surface, Part.Cylinder)) adjacent = [i for i, face in enumerate(rounded.Faces, 1) if isinstance(face.Surface, Part.Plane) and any(edge.isSame(other) for edge in fillet.Edges if isinstance(edge.Curve, Part.Line) for other in face.Edges)] document = App.newDocument("LivingHingeCorner") source = document.addObject("Part::Feature", "RoundedCorner") source.Shape = rounded source.Label = "Select Faces " + ", ".join(str(i) for i in sorted([index] + adjacent)) document.recompute() document.saveAs(str(folder / "living-hinge-corner.FCStd")) export_dxf(decompose(rounded, [index] + adjacent, settings), folder / "living-hinge-corner.dxf") App.closeDocument(document.Name) cross_file = folder / "cross-cut.FCStd" if cross_file.exists(): # Read saved topology; older FreeCAD cannot reliably recompute this tree. with ZipFile(cross_file) as archive: cross = Part.Shape() cross.importBrepFromString(archive.read("Body.Shape.brp").decode("utf-8")) export_dxf(decompose(cross, [1, 2, 3, 4, 5, 6, 9, 10, 14, 18], settings), folder / "cross-cut-3mm.dxf") export_dxf(decompose(cross, range(1, len(cross.Faces) + 1), settings), folder / "cross-cut-all-faces-3mm.dxf") print("Examples written to " + str(folder))
if __name__ == "__main__": create_examples()