Skip to main content

Convert SVG and DXF files to Prusa Core One G-code for plastic welding

Project description

MicroWeldr

PyPI version Test Suite CodeQL

A Python package that converts SVG and DXF files to Prusa Core One G-code for continuous plastic line welding. The package processes vector graphics and generates G-code that creates waterproof welded lines by placing many precise weld "dots" in sequence along the paths, without extruding any plastic material.

Multi-Format Support - Processes both SVG and DXF files with automatic weld type detection based on colors, layers, or filenames.

Optimized for Prusa Core One: Includes chamber temperature control (M141/M191), proper bed dimensions (250ร—220ร—270mm), and CoreXY-specific settings for reliable plastic welding operations.

This enables rapid microfluidics prototyping with a 3D printer by creating sealed, waterproof channels and barriers. Each vector path becomes a continuous welded line through precisely controlled sequential dot placement.

MicroWeldr Animation

Complete welding process showing both normal welds (blue) and frangible welds (red) with 1mm spacing and 2mm diameter dots representing actual welding spots

๐Ÿ†• Version 6.0.0 - Production Ready

  • Unified Configuration: Consistent 1mm dot spacing across SVG and DXF formats
  • Professional Examples: Complete example collection with combined weld types
  • Improved Animations: Uniform timing with 3-second pause for final result viewing
  • Proper Weld Heights: 0.1mm normal welds, 0.6mm frangible welds for breakaway functionality
  • Comprehensive Testing: Full test coverage including weld height validation
  • Modern Dependencies: Updated to pytest 9.0.1, pre-commit 4.4.0, optimized package set
  • CI/CD Ready: Complete GitHub Actions workflows with multi-platform testing

Project Structure

microweldr/
โ”œโ”€โ”€ microweldr/           # Main package
โ”‚   โ”œโ”€โ”€ core/            # Core functionality & configuration
โ”‚   โ”‚   โ”œโ”€โ”€ config.py          # Configuration management
โ”‚   โ”‚   โ”œโ”€โ”€ unified_config.py  # Unified configuration system
โ”‚   โ”‚   โ”œโ”€โ”€ data_models.py     # Structured data models
โ”‚   โ”‚   โ”œโ”€โ”€ events.py          # Event system for processing
โ”‚   โ”‚   โ””โ”€โ”€ constants.py       # Application constants
โ”‚   โ”œโ”€โ”€ parsers/         # File format parsers
โ”‚   โ”‚   โ”œโ”€โ”€ dxf_reader.py      # DXF file processing
โ”‚   โ”‚   โ”œโ”€โ”€ svg_parser.py      # SVG file processing
โ”‚   โ”‚   โ””โ”€โ”€ enhanced_svg_parser.py # Advanced SVG features
โ”‚   โ”œโ”€โ”€ generators/      # Point and G-code generation
โ”‚   โ”‚   โ”œโ”€โ”€ point_iterator_factory.py # Factory pattern for iterators
โ”‚   โ”‚   โ”œโ”€โ”€ svg_point_iterator.py     # SVG point generation
โ”‚   โ”‚   โ””โ”€โ”€ dxf_point_iterator.py     # DXF point generation
โ”‚   โ”œโ”€โ”€ outputs/         # Output generation
โ”‚   โ”‚   โ”œโ”€โ”€ streaming_gcode_subscriber.py # G-code generation
โ”‚   โ”‚   โ””โ”€โ”€ gif_animation_subscriber.py   # Animation generation
โ”‚   โ”œโ”€โ”€ cli/             # Command line interface
โ”‚   โ”‚   โ”œโ”€โ”€ simple_main.py     # Main CLI entry point
โ”‚   โ”‚   โ””โ”€โ”€ enhanced_main.py   # Advanced CLI features
โ”‚   โ””โ”€โ”€ prusalink/       # Printer integration
โ”œโ”€โ”€ tests/               # Comprehensive test suite
โ”‚   โ”œโ”€โ”€ unit/           # Unit tests (121 tests)
โ”‚   โ”œโ”€โ”€ parsing/        # Parser tests
โ”‚   โ”œโ”€โ”€ outputs/        # Output generation tests
โ”‚   โ””โ”€โ”€ test_linting.py # Code quality tests
โ”œโ”€โ”€ examples/           # Professional example collection
โ”‚   โ”œโ”€โ”€ flask_simple.svg        # SVG example (628 points)
โ”‚   โ”œโ”€โ”€ flask.dxf              # DXF example (467 points)
โ”‚   โ”œโ”€โ”€ combined_normal.dxf     # Combined example (801 points)
โ”‚   โ”œโ”€โ”€ combined_frangible.dxf  # Frangible welds (5 points)
โ”‚   โ””โ”€โ”€ *.gif                  # Generated animations
โ””โ”€โ”€ pyproject.toml     # Modern Poetry configuration (PEP 621)

Features

File Format Support

  • SVG Files: Paths, lines, circles, rectangles, groups, and use elements
  • DXF Files: Lines, arcs, circles, polylines, and LWPOLYLINES
  • Multi-File Processing: Mix SVG and DXF files in single command
  • Unit Validation: DXF files must use millimeters (throws exception otherwise)
  • Construction Filtering: Automatically ignores construction layers in DXF

Weld Type Detection

Multiple methods for determining weld types:

1. Color-Based (SVG)

  • Black elements โ†’ Normal welds
  • Blue elements โ†’ Frangible welds (breakaway seals)
  • Red elements โ†’ Stop points (pause for user intervention)
  • Magenta elements โ†’ Pipette points (filling operations)

2. Layer-Based (DXF)

  • Normal layers: Any layer name
  • Frangible layers: Containing frangible, light, break, seal, weak
  • Construction layers: Containing construction, const, guide, reference, ref (ignored)

3. Filename-Based (Fallback)

When colors/layers don't specify weld type, filenames are checked:

  • Normal welds: main_welds.dxf, structure.svg
  • Frangible welds: frangible_seals.dxf, light_welds.svg, break_points.dxf

Advanced Features

  • Configurable Parameters: TOML-based configuration for temperatures, heights, and timing
  • Multi-Pass Welding: Configurable initial and final dot spacing
  • Optimized Z Movement: Separate weld move height for faster intra-path welding
  • Chamber Temperature Control: Prusa Core One chamber heating
  • Animation Output: Generates animated SVG showing the welding sequence
  • Proper G-code Structure: Includes heating, cooling, and safety procedures
  • Error Handling: Comprehensive error reporting and recovery
  • Statistics Collection: Processing metrics and validation results

Installation

From PyPI

pip install microweldr

With DXF Support

pip install microweldr[dxf]  # Includes ezdxf for DXF processing

From Source

git clone https://github.com/retospect/microweldr.git
cd microweldr
poetry install --with dev

Quick Start

Basic Usage

# Convert single SVG file
microweldr -weld design.svg -g_out output.gcode

# Convert DXF file with unit validation
microweldr -weld drawing.dxf -g_out output.gcode

# Process combined normal and frangible welds
microweldr -weld main_welds.dxf -frange frangible_seals.dxf -g_out combined.gcode

# Generate animation along with G-code
microweldr -weld design.svg -g_out output.gcode -animation output_animation.gif

Fusion 360 Workflow

Perfect for CAD-based microfluidics design:

  1. Design in Fusion 360: Create your microfluidic channels and seals
  2. Export two DXF files:
    • main_welds.dxf - Primary structural welds
    • frangible_seals.dxf - Breakaway seals for filling ports
  3. Process both files: microweldr -weld main_welds.dxf -frange frangible_seals.dxf -g_out device.gcode
  4. Print: Load G-code on Prusa Core One

Configuration

Create microweldr_config.toml for custom settings:

[printer]
bed_x = 250
bed_y = 220
bed_z = 270
chamber_temperature = 45

[movement]
move_height = 5.0  # mm - height for safe movement between paths
weld_height = 0.02  # mm - height for actual welding (touching plastic)
weld_move_height = 2.0  # mm - height for moving between weld points (faster than safe height)
frame_height = 10.0  # mm - height for frame drawing (clearance check)
travel_speed = 3000  # mm/min - travel speed for movements
z_speed = 600  # mm/min - optimized Z speed (near maximum safe limit for Core One)

[normal_welds]
weld_height = 0.1           # mm - structural weld depth
weld_temperature = 160      # ยฐC - nozzle temperature
weld_time = 0.1            # seconds - dwell time
dot_spacing = 0.5          # mm - unified spacing

[frangible_welds]
weld_height = 0.6          # mm - deeper for breakaway functionality
weld_temperature = 160     # ยฐC - same temperature
weld_time = 0.3           # seconds - longer for controlled weakness
dot_spacing = 0.5         # mm - unified spacing

[output]
gcode_extension = ".gcode"
animation_extension = "_animation.svg"

Command Reference

Main Command

microweldr [OPTIONS]

Options:
  -weld PATH           Normal weld file (SVG or DXF)
  -frange PATH         Frangible weld file (SVG or DXF)
  -g_out PATH          Output G-code file
  -animation PATH      Output animation GIF file
  -quiet              Suppress verbose output
  --help              Show help message

Examples

# Single file processing
microweldr -weld design.svg -g_out output.gcode

# Combined weld types
microweldr -weld structural.dxf -frange seals.dxf -g_out device.gcode

# With animation
microweldr -weld design.svg -animation preview.gif -g_out output.gcode

File Format Details

SVG Support

  • Elements: <path>, <line>, <circle>, <rect>, <g>, <use>
  • Attributes: stroke, class, id for weld type detection
  • Namespaces: Handles standard SVG namespaces
  • Definitions: Processes <defs> and referenced elements

DXF Support

  • Entities: LINE, ARC, CIRCLE, POLYLINE, LWPOLYLINE
  • Units: Must be millimeters (validated automatically)
  • Layers: Used for weld type and construction detection
  • Coordinate System: Preserves original coordinates

Weld Type Examples

Filename-Based Detection

# These filenames automatically detect frangible welds:
microweldr convert frangible_seals.dxf      # โ†’ Frangible
microweldr convert light_connections.svg    # โ†’ Frangible
microweldr convert break_points.dxf         # โ†’ Frangible
microweldr convert seal_layer.svg           # โ†’ Frangible

# These default to normal welds:
microweldr convert main_structure.dxf       # โ†’ Normal
microweldr convert primary_welds.svg        # โ†’ Normal

Layer-Based Detection (DXF)

Layer "main_welds"        โ†’ Normal welds
Layer "frangible_seals"   โ†’ Frangible welds
Layer "construction"      โ†’ Ignored
Layer "break_points"      โ†’ Frangible welds

Development

Running Tests

poetry run pytest                    # All tests
poetry run pytest tests/unit/       # Unit tests only
poetry run pytest -v               # Verbose output

Code Quality

poetry run black .                  # Format code
poetry run bandit -r microweldr/   # Security check
poetry run pre-commit run --all-files  # All checks

Building

poetry build                        # Build wheel and source
poetry install dist/*.whl          # Install local build

Examples

Professional Examples

# See examples/ directory for complete example collection:
# - flask_simple.svg (628 points, Bรฉzier curves)
# - flask.dxf (467 points, line interpolation)
# - combined_normal.dxf + combined_frangible.dxf (806 total points)

# Process the combined example
microweldr -weld examples/combined_normal.dxf \
           -frange examples/combined_frangible.dxf \
           -g_out examples/combined_animation.gif \
           -animation examples/combined_animation.gif

Production Workflow

# 1. Design in CAD software (Fusion 360, etc.)
# 2. Export separate files for different weld types
# 3. Process with MicroWeldr
microweldr -weld structural_welds.dxf -frange breakaway_seals.dxf -g_out device.gcode

# 4. Load G-code on Prusa Core One and print

Troubleshooting

DXF Issues

  • Unit Error: Ensure DXF uses millimeters in drawing units
  • No Entities: Check that layers contain supported entities (lines, arcs, circles)
  • Construction Layers: Rename layers to avoid construction keywords

SVG Issues

  • No Paths: Ensure elements have stroke attribute (not just fill)
  • Complex Paths: Curves are approximated with line segments
  • Nested Groups: Deep nesting may affect processing

Weld Type Detection

  • Wrong Type: Check filename, layer names, or SVG colors
  • All Normal: Add frangible keywords to filenames or layers
  • All Frangible: Remove frangible keywords from filenames

Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature-name
  3. Make changes with tests: poetry run pytest
  4. Format code: poetry run black .
  5. Submit pull request

License

MIT License - see LICENSE file for details.

Changelog

Version 5.3.0 (Latest)

  • NEW: Full DXF file support with ezdxf integration
  • NEW: Multi-file processing (mix SVG and DXF)
  • NEW: Filename-based weld type detection as fallback
  • BREAKING: Renamed "light_welds" to "frangible_welds" in all configs
  • IMPROVED: Modular CLI architecture with better error handling
  • IMPROVED: Publisher-subscriber file processing framework
  • IMPROVED: Comprehensive test coverage (33 tests)
  • IMPROVED: Structured data models with validation

Version 5.2.x

  • Enhanced SVG processing
  • Animation improvements
  • Configuration validation

Version 5.1.x

  • Initial public release
  • Basic SVG to G-code conversion
  • Prusa Core One optimization

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

microweldr-6.0.0.tar.gz (144.4 kB view details)

Uploaded Source

Built Distribution

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

microweldr-6.0.0-py3-none-any.whl (175.6 kB view details)

Uploaded Python 3

File details

Details for the file microweldr-6.0.0.tar.gz.

File metadata

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

File hashes

Hashes for microweldr-6.0.0.tar.gz
Algorithm Hash digest
SHA256 72c0139d3c39b2e3dec84f1dc6762b789fc85bf4be4479f8e742402f274620de
MD5 b65f967e003b1da5e29193646c3af3b7
BLAKE2b-256 a5edea309dfb760b90ff275f12c60c8f073ffd3bc6f861b36153db0cd99ccdee

See more details on using hashes here.

Provenance

The following attestation bundles were made for microweldr-6.0.0.tar.gz:

Publisher: pypi_publish.yml on retospect/microweldr

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

File details

Details for the file microweldr-6.0.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for microweldr-6.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 646041d554931fa8b859f6abcbdd6bf457ba5b932689d788479cd63ebb63bf7a
MD5 a8b41eaee83a6c23effbf58ff3dcc408
BLAKE2b-256 b04b656b2c2a954e39680fcaa88cda0eadf75adf9c627fc54706e7c8d4c43680

See more details on using hashes here.

Provenance

The following attestation bundles were made for microweldr-6.0.0-py3-none-any.whl:

Publisher: pypi_publish.yml on retospect/microweldr

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