Pronounced "mor-FAY" (from Greek μορφή, meaning "form" or "shape")
A CAD-agnostic 2D sketch geometry and constraint representation with adapter support for FreeCAD, Fusion 360, SolidWorks, and Autodesk Inventor.
This project provides:
morphe: Platform-independent schema for 2D sketch geometry and constraintsmorphe.adapters.freecad: Adapter for FreeCAD's Sketcher workbenchmorphe.adapters.fusion: Adapter for Autodesk Fusion 360morphe.adapters.solidworks: Adapter for SolidWorks (Windows only, via COM)morphe.adapters.inventor: Adapter for Autodesk Inventor (Windows only, via COM)
The canonical format enables constrained sketches to be stored, transferred, and manipulated independently of any specific CAD system.
See SPECIFICATION.md for the complete technical specification, including supported geometry types, constraints, JSON schema format, and platform-specific adapter details.
pip install -e .| Adapter | Platform | Requirements |
|---|---|---|
| FreeCAD | Linux, macOS, Windows | FreeCAD installed and accessible via PYTHONPATH |
| Fusion 360 | Windows, macOS | Run from within Fusion 360's Python environment |
| SolidWorks | Windows only | SolidWorks installed, pywin32 package |
| Inventor | Windows only | Autodesk Inventor installed, pywin32 package |
For Windows COM-based adapters (SolidWorks, Inventor):
pip install pywin32from morphe import (
SketchDocument, Point2D, Line, Circle, Horizontal, Radius,
save_sketch, load_sketch
)
# Create a sketch
sketch = SketchDocument(name="MySketch")
line_id = sketch.add_primitive(Line(start=Point2D(0, 0), end=Point2D(100, 0)))
circle_id = sketch.add_primitive(Circle(center=Point2D(50, 50), radius=20))
sketch.add_constraint(Horizontal(line_id))
sketch.add_constraint(Radius(circle_id, 20))
save_sketch(sketch, "my_sketch.json")
# Load from file
sketch = load_sketch("my_sketch.json")from morphe import load_sketch
from morphe.adapters.freecad import FreeCADAdapter
sketch = load_sketch("my_sketch.json")
adapter = FreeCADAdapter()
adapter.create_sketch(sketch.name)
adapter.load_sketch(sketch)
status, dof = adapter.get_solver_status()
print(f"Status: {status.name}, DOF: {dof}")
adapter.close_sketch()The Fusion 360 adapter runs as a script or add-in within Fusion 360:
# Run this inside Fusion 360's Scripts environment
import sys
sys.path.insert(0, r"path/to/morphe-repo")
from morphe import load_sketch
from morphe.adapters.fusion import FusionAdapter
def run(context):
sketch = load_sketch("my_sketch.json")
adapter = FusionAdapter()
adapter.create_sketch(sketch.name)
adapter.load_sketch(sketch)
# Export back to canonical format
exported = adapter.export_sketch()
print(f"Exported {len(exported.primitives)} primitives")
status, dof = adapter.get_solver_status()
print(f"Status: {status.name}, DOF: {dof}")The SolidWorks adapter uses COM automation via pywin32 (Windows only):
from morphe import load_sketch
from morphe.adapters.solidworks import SolidWorksAdapter, SOLIDWORKS_AVAILABLE
if SOLIDWORKS_AVAILABLE:
sketch = load_sketch("my_sketch.json")
adapter = SolidWorksAdapter()
adapter.create_sketch(sketch.name)
adapter.load_sketch(sketch)
# Export back to canonical format
exported = adapter.export_sketch()
print(f"Exported {len(exported.primitives)} primitives")
status, dof = adapter.get_solver_status()
print(f"Status: {status.name}, DOF: {dof}")Notes:
- Requires SolidWorks to be installed and running (or will launch automatically)
- The adapter connects to an existing SolidWorks instance or starts a new one
- Sketches are created on the Front Plane by default (XY plane)
- Dimensional constraints use geometry recreation to avoid blocking dialogs
Supported Features:
- All primitive types: Line, Arc, Circle, Point, Spline, Ellipse, EllipticalArc
- All geometric constraints: Coincident, Tangent, Parallel, Perpendicular, Horizontal, Vertical, Equal, Concentric, Collinear, Midpoint, Fixed, Symmetric
- All dimensional constraints: Length, Radius, Diameter, Angle, Distance, DistanceX, DistanceY
- Construction geometry
- Solver status and DOF reporting
The Inventor adapter uses COM automation via pywin32 (Windows only):
from morphe import load_sketch
from morphe.adapters.inventor import InventorAdapter, INVENTOR_AVAILABLE
if INVENTOR_AVAILABLE:
sketch = load_sketch("my_sketch.json")
adapter = InventorAdapter()
adapter.create_sketch(sketch.name)
adapter.load_sketch(sketch)
# Export back to canonical format
exported = adapter.export_sketch()
print(f"Exported {len(exported.primitives)} primitives")
status, dof = adapter.get_solver_status()
print(f"Status: {status.name}, DOF: {dof}")Notes:
- Requires Autodesk Inventor to be installed and running (or will launch automatically)
- The adapter connects to an existing Inventor instance or starts a new one
- Sketches are created on the XY plane by default
Supported Features:
- All primitive types: Line, Arc, Circle, Point, Spline, Ellipse, EllipticalArc
- All geometric constraints: Coincident, Tangent, Parallel, Perpendicular, Horizontal, Vertical, Equal, Concentric, Collinear, Midpoint, Fixed, Symmetric
- All dimensional constraints: Length, Radius, Diameter, Angle, Distance, DistanceX, DistanceY
- Construction geometry
- Solver status and DOF reporting
For GUI tools or external scripts that need to communicate with CAD applications, each adapter provides an RPC server/client pair.
FreeCAD (run in FreeCAD's Python console):
from morphe.adapters.freecad import start_server
start_server() # localhost:9876Fusion 360 (install the MorpheServer add-in from morphe/adapters/fusion/addin/MorpheServer/):
cd morphe/adapters/fusion/addin
python setup_addin.py installThe server starts automatically when Fusion 360 launches (localhost:9879).
SolidWorks (run with SolidWorks open):
from morphe.adapters.solidworks import start_server
start_server() # localhost:9878Inventor (run with Inventor open):
from morphe.adapters.inventor import start_server
start_server() # localhost:9877All clients share the same interface:
from morphe.adapters.freecad import FreeCADClient
# or: from morphe.adapters.fusion import FusionClient
# or: from morphe.adapters.solidworks import SolidWorksClient
# or: from morphe.adapters.inventor import InventorClient
client = FreeCADClient()
if client.connect():
# List available sketches
sketches = client.list_sketches()
# Export a sketch to canonical format
sketch = client.export_sketch("Sketch")
# Import a sketch into the CAD application
client.import_sketch(my_sketch, name="NewSketch")
# Get solver status
status, dof = client.get_solver_status("Sketch")Core tests (no CAD software required):
pytest tests/ # All tests
pytest tests/ --cov # With coverageFreeCAD adapter tests (requires FreeCAD):
pytest tests/test_freecad_roundtrip.py -vFusion 360 adapter tests (run from within Fusion 360):
The Fusion 360 test suite (73 tests) must be run as a script inside Fusion 360:
- Open Fusion 360
- Go to Utilities > Add-Ins > Scripts
- Add and run the test script from
morphe/adapters/fusion/script/MorpheTests/
SolidWorks adapter tests (requires SolidWorks on Windows):
pytest tests/test_solidworks_roundtrip.py -vThe SolidWorks test suite includes 80 tests covering:
- Basic and complex geometry primitives
- All constraint types including symmetric constraints
- Solver status detection
- Precision and edge cases
- Arc variations and tangent constraints
Inventor adapter tests (requires Inventor on Windows):
pytest tests/test_inventor_roundtrip.py -vTests cover all primitives, constraints, solver status, and edge cases.
- SketchBridge - Desktop application for transferring sketches between CAD systems using Morphe
MIT - see LICENSE for details.