Skip to main content

A python library to make Gridfinity compatible objects with CadQuery.

Project description

microfinity

PyPI python version CadQuery cq-kit license code style: black

A Python library to make Gridfinity compatible objects with CadQuery.

The Gridfinity system was created by Zach Freedman as a versatile system of modular organization and storage modules. This library provides Python classes to create parameterized Gridfinity components including boxes, baseplates, drawer spacers, and rugged storage boxes.

Note: This is a fork of cq-gridfinity by Michael Gale.

Installation

pip install microfinity

Or install from source:

git clone https://github.com/nullstack65/microfinity.git
cd microfinity
pip install -e .

Dependencies

Quick Start

import microfinity
print(microfinity.__version__)
from microfinity import *

# Make a simple box
box = GridfinityBox(3, 2, 5, holes=True, scoops=True, labels=True)
box.save_stl_file()
# Output: gf_box_3x2x5_holes_scoops_labels.stl

CLI Commands

microfinity-box

microfinity-box 2 3 5 -m -f stl

microfinity-base

microfinity-base 7 4 -s -f stl

microfinity-rugged

microfinity-rugged 5 4 6 --box --lid -f stl

Classes

Geometry Classes

  • GridfinityBox - Boxes with dividers, scoops, labels, magnet holes
  • GridfinitySolidBox - Solid boxes without interior cutout
  • GridfinityBaseplate - Baseplates with optional mounting tabs and notches
  • GridfinityBaseplateLayout - Tiled baseplate layouts with automatic partitioning for large prints
  • GridfinityConnectionClip - Connection clips for joining baseplate pieces
  • GridfinityDrawerSpacer - Spacers for fitting baseplates in drawers
  • GridfinityRuggedBox - Rugged storage boxes with lids and handles

Utility Classes

  • GridfinityExporter - Export utility for STEP, STL, SVG formats
  • SVGView - Enum for SVG view directions

Enums

  • EdgeMode - Edge treatment options for baseplate layouts
  • SegmentationMode - Partitioning strategies for large baseplates
  • ToleranceMode - Tolerance handling for baseplate fitting

Export

The GridfinityExporter class provides a unified interface for exporting Gridfinity objects to various file formats.

Basic Usage

from microfinity import GridfinityBox, GridfinityExporter, SVGView

# Create a box
box = GridfinityBox(2, 2, 4, holes=True)

# Export using the exporter
exporter = GridfinityExporter(box)
exporter.save_step_file("box.step")
exporter.save_stl_file("box.stl")
exporter.save_svg_file("box.svg", view=SVGView.ISOMETRIC)

Direct Class Methods (Backward Compatible)

All geometry classes also have export methods directly available:

box = GridfinityBox(2, 2, 4)
box.save_stl_file()  # Auto-generates filename based on parameters
box.save_step_file("custom_name.step")
box.save_svg_file("preview.svg")

SVG Views

The SVGView enum provides the following view options:

View Description
SVGView.FRONT Front view (+Y direction)
SVGView.BACK Back view (-Y direction)
SVGView.LEFT Left view (-X direction)
SVGView.RIGHT Right view (+X direction)
SVGView.TOP Top view (+Z direction)
SVGView.BOTTOM Bottom view (-Z direction)
SVGView.ISOMETRIC Isometric view (default)

Export Options

exporter = GridfinityExporter(obj)

# STL with custom tolerance
exporter.save_stl_file("output.stl", tolerance=0.01, angular_tolerance=0.1)

# SVG with custom styling
exporter.save_svg_file(
    "output.svg",
    view=SVGView.TOP,
    line_width=0.5,
    show_hidden=False
)

Baseplate Layout Export

GridfinityBaseplateLayout has additional export methods for batch exporting all pieces:

from microfinity import GridfinityBaseplateLayout

layout = GridfinityBaseplateLayout(
    length_mm=300,
    width_mm=200,
    max_piece_u=4
)

# Export all pieces and clips
results = layout.export_all(
    output_dir="./output",
    formats=["stl", "step"],
    prefix="my_baseplate"
)

# Export preview SVGs only
layout.export_preview(output_dir="./previews")

Development

python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
pytest

Running Tests

# Run all tests
pytest

# Run with coverage
pytest --cov=microfinity

# Run specific test file
pytest tests/test_box.py

# Update golden test baselines
UPDATE_GOLDEN=1 pytest tests/test_golden.py

References

License

MIT License. Originally created by Michael Gale.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

microfinity-1.0.0.tar.gz (79.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

microfinity-1.0.0-py3-none-any.whl (71.9 kB view details)

Uploaded Python 3

File details

Details for the file microfinity-1.0.0.tar.gz.

File metadata

  • Download URL: microfinity-1.0.0.tar.gz
  • Upload date:
  • Size: 79.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for microfinity-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ad8835c797543ecf2aa865992977f8a0074cababda12a19ed26252a64563ab42
MD5 edac2aeffed27633b271951983ba35f6
BLAKE2b-256 384d6c5a1c4d13653a57a992056687f9c7cbaa4e5c56ff0f1bf3d8d3dbd4b8c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for microfinity-1.0.0.tar.gz:

Publisher: release-please.yml on nullStack65/microfinity

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file microfinity-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: microfinity-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 71.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for microfinity-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 73a094e96d334366cf4be59e0c39c37f0a8a52727772576a782705afecdfa8d6
MD5 a5204a0a7d990836f2393cf9eb702d8f
BLAKE2b-256 fb07eb6b1b963ef22e4e4b286cc6b3fe9e62edadd7a41a69c14414c55705fa7f

See more details on using hashes here.

Provenance

The following attestation bundles were made for microfinity-1.0.0-py3-none-any.whl:

Publisher: release-please.yml on nullStack65/microfinity

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page