Skip to content

Repository files navigation

Morphe

Pronounced "mor-FAY" (from Greek μορφή, meaning "form" or "shape")

TestsPyPI versionPyPI downloadsPython 3.10+License: MIT

A CAD-agnostic 2D sketch geometry and constraint representation with adapter support for FreeCAD, Fusion 360, SolidWorks, and Autodesk Inventor.

Overview

This project provides:

  • morphe: Platform-independent schema for 2D sketch geometry and constraints
  • morphe.adapters.freecad: Adapter for FreeCAD's Sketcher workbench
  • morphe.adapters.fusion: Adapter for Autodesk Fusion 360
  • morphe.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.

Installation

pip install -e .

Platform-Specific Requirements

AdapterPlatformRequirements
FreeCADLinux, macOS, WindowsFreeCAD installed and accessible via PYTHONPATH
Fusion 360Windows, macOSRun from within Fusion 360's Python environment
SolidWorksWindows onlySolidWorks installed, pywin32 package
InventorWindows onlyAutodesk Inventor installed, pywin32 package

For Windows COM-based adapters (SolidWorks, Inventor):

pip install pywin32

Quick Start

frommorpheimport (
SketchDocument, Point2D, Line, Circle, Horizontal, Radius,
save_sketch, load_sketch
)
# Create a sketchsketch=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 filesketch=load_sketch("my_sketch.json")

FreeCAD Integration

frommorpheimportload_sketchfrommorphe.adapters.freecadimportFreeCADAdaptersketch=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()

Fusion 360 Integration

The Fusion 360 adapter runs as a script or add-in within Fusion 360:

# Run this inside Fusion 360's Scripts environmentimportsyssys.path.insert(0, r"path/to/morphe-repo")
frommorpheimportload_sketchfrommorphe.adapters.fusionimportFusionAdapterdefrun(context):
sketch=load_sketch("my_sketch.json")
adapter=FusionAdapter()
adapter.create_sketch(sketch.name)
adapter.load_sketch(sketch)
# Export back to canonical formatexported=adapter.export_sketch()
print(f"Exported {len(exported.primitives)} primitives")
status, dof=adapter.get_solver_status()
print(f"Status: {status.name}, DOF: {dof}")

SolidWorks Integration

The SolidWorks adapter uses COM automation via pywin32 (Windows only):

frommorpheimportload_sketchfrommorphe.adapters.solidworksimportSolidWorksAdapter, SOLIDWORKS_AVAILABLEifSOLIDWORKS_AVAILABLE:
sketch=load_sketch("my_sketch.json")
adapter=SolidWorksAdapter()
adapter.create_sketch(sketch.name)
adapter.load_sketch(sketch)
# Export back to canonical formatexported=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

Inventor Integration

The Inventor adapter uses COM automation via pywin32 (Windows only):

frommorpheimportload_sketchfrommorphe.adapters.inventorimportInventorAdapter, INVENTOR_AVAILABLEifINVENTOR_AVAILABLE:
sketch=load_sketch("my_sketch.json")
adapter=InventorAdapter()
adapter.create_sketch(sketch.name)
adapter.load_sketch(sketch)
# Export back to canonical formatexported=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

RPC Server Mode

For GUI tools or external scripts that need to communicate with CAD applications, each adapter provides an RPC server/client pair.

Starting Servers

FreeCAD (run in FreeCAD's Python console):

frommorphe.adapters.freecadimportstart_serverstart_server() # localhost:9876

Fusion 360 (install the MorpheServer add-in from morphe/adapters/fusion/addin/MorpheServer/):

cd morphe/adapters/fusion/addin
python setup_addin.py install

The server starts automatically when Fusion 360 launches (localhost:9879).

SolidWorks (run with SolidWorks open):

frommorphe.adapters.solidworksimportstart_serverstart_server() # localhost:9878

Inventor (run with Inventor open):

frommorphe.adapters.inventorimportstart_serverstart_server() # localhost:9877

Using Clients

All clients share the same interface:

frommorphe.adapters.freecadimportFreeCADClient# or: from morphe.adapters.fusion import FusionClient# or: from morphe.adapters.solidworks import SolidWorksClient# or: from morphe.adapters.inventor import InventorClientclient=FreeCADClient()
ifclient.connect():
# List available sketchessketches=client.list_sketches()
# Export a sketch to canonical formatsketch=client.export_sketch("Sketch")
# Import a sketch into the CAD applicationclient.import_sketch(my_sketch, name="NewSketch")
# Get solver statusstatus, dof=client.get_solver_status("Sketch")

Running Tests

Core tests (no CAD software required):

pytest tests/ # All tests
pytest tests/ --cov # With coverage

FreeCAD adapter tests (requires FreeCAD):

pytest tests/test_freecad_roundtrip.py -v

Fusion 360 adapter tests (run from within Fusion 360):

The Fusion 360 test suite (73 tests) must be run as a script inside Fusion 360:

  1. Open Fusion 360
  2. Go to Utilities > Add-Ins > Scripts
  3. 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 -v

The 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 -v

Tests cover all primitives, constraints, solver status, and edge cases.

Related Projects

  • SketchBridge - Desktop application for transferring sketches between CAD systems using Morphe

License

MIT - see LICENSE for details.

About

CAD-agnostic 2D sketch geometry and constraint representation with adapters for FreeCAD, Fusion 360, Autodesk Inventor and SolidWorks

Topics

Resources

Contributing

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages