Skip to main content

Python library for automated DXF file marking and manipulation

Project description

SnapMark

SnapMark is a Python-based tool designed to apply customizable markings to DXF files using a flexible sequence logic. It leverages the ezdxf library to manipulate DXF files and supports operations like adding counters, alignment, character scaling, and more.

SnapMark is a Python library for adding customizable text markings to DXF (AutoCAD) files. Built on top of ezdxf, it provides a simple API for batch processing, custom sequences, and automated workflows.

PyPI version Python 3.8+ License: MIT

Installation

pip install snapmark

Quick Start

import snapmark as sm

# Mark all DXF files with their filename
sm.mark_by_name("path/to/drawings")

# Custom sequence: filename + folder name
seq = (sm.SequenceBuilder()
       .file_name()
       .folder(num_chars=2)   # firts 2 chars of folder name
       .build())

sm.mark_with_sequence("path/to/drawings", seq, scale_factor=100)

Features

  • Simple API - Mark files in one line
  • Custom sequences - Build complex marking logic with SequenceBuilder
  • Batch operations - Process entire folders with IterationManager
  • Built-in backup - Automatic .bak files before modifications
  • Hole counting - Count and analyze circles in drawings
  • Extensible - Easy to add custom operations

Use Cases

  • Manufacturing: Add part numbers and quantities to production drawings
  • CAM workflows: Automatically mark drawings before CNC processing
  • Quality control: Count holes and verify drawing specifications
  • Batch processing: Apply consistent markings across large drawing sets

Examples

Basic Marking

import snapmark as sm

# Mark with filename (simplest)
sm.mark_by_name("drawings/")

# Mark with first part of filename (e.g., "PART" from "PART_123_Q5.dxf")
sm.mark_by_name_part("drawings/", separator='_', part_index=0)

Custom Sequences

import snapmark as sm

# Extract part number from filename like "S532_P5_SP4_Q2.dxf"
def extract_part_number(folder, filename):
    import re
    match = re.search(r'P(\d+)', filename)
    return f"P{match.group(1)}" if match else ""

seq = (sm.SequenceBuilder()
       .file_part(separator='_', part_index=0)  # "S532"
       .custom(extract_part_number)              # "P5"
       .build())

sm.mark_with_sequence("drawings/", seq)
# Result: "S532-P5"

Count Holes

import snapmark as sm

# Simple count
stats = sm.quick_count_holes("drawings/", min_diam=5, max_diam=10)
print(f"Total holes: {stats['total_count']}")

# With multiplier (extract quantity from filename, e.g. S532_P1_S235JR_SP4_Q2 where Q determines the number of identical pieces to cut) 
def get_quantity(filename):
    import re
    match = re.search(r'Q(\d+)', filename)
    return int(match.group(1)) if match else 1

stats = sm.quick_count_holes(
    "drawings/", 
    min_diam=5, 
    max_diam=10,
    multiplier=get_quantity
)
print(f"Total holes (with qty): {stats['total_count']}")

Advanced Pipeline

import snapmark as sm

# Multiple operations in sequence
seq = sm.SequenceBuilder().file_name().build()

manager = sm.IterationManager("drawings/", use_backup_system=True)
manager.add_operation(
    sm.Aligner(),                    # Align drawing
    sm.AddMark(seq, scale_factor=100),  # Add marking
    sm.CountHoles(sm.find_circle_by_radius(5, 10))  # Count holes
)
manager.execute()

Single File Processing

import snapmark as sm

seq = sm.SequenceBuilder().file_name().build()

sm.process_single_file(
    "drawing.dxf",
    sm.Aligner(),
    sm.AddMark(seq, scale_factor=100),
    sm.AddX(sm.find_circle_by_radius(5, 10), x_size=8), # Replaces 5–10mm holes with X marks for manual drilling
    use_backup=True
)

Restore Backups

import snapmark as sm

# Undo all changes
sm.restore_backup("drawings/")

# Restore recursively in subfolders
sm.restore_backup("drawings/", recursive=True)

# Restore but keep .bak files
sm.restore_backup("drawings/", delete_backups=False)

API Overview

Shortcuts (Simple Usage)

  • mark_by_name(folder) - Mark with filename
  • mark_by_name_part(folder, separator, part_index) - Mark with filename part
  • mark_with_sequence(folder, sequence) - Mark with custom sequence
  • quick_count_holes(folder, min_diam, max_diam) - Count holes
  • restore_backup(folder) - Restore from backups
  • process_single_file(file, *operations) - Pipeline on single file

SequenceBuilder (Custom Sequences)

seq = (sm.SequenceBuilder()
       .file_name()                    # Full filename
       .file_part(separator, index)    # Split filename
       .folder(num_chars)              # Folder name
       .literal("text")                # Fixed text
       .custom(function)               # Custom function
       .set_separator("-")             # Join character
       .build())

Operations (Advanced)

  • AddMark(sequence) - Add text marking
  • Aligner() - Aligns the drawing along its longest side in the X direction.
  • CountHoles(find_func) - Count circles
  • AddX(find_func, x_size) - Add X marks
  • RemoveCircle(find_func) - Remove circles
  • SubstituteCircle(find_func, new_radius) - Replace circles

IterationManager (Batch Processing)

manager = sm.IterationManager(folder, use_backup_system=True)
manager.add_operation(operation1, operation2, ...)
manager.execute(recursive=False)

Requirements

  • Python 3.8+
  • ezdxf >= 1.0.0

Documentation

For detailed documentation and more examples, visit the GitHub repository.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License - see LICENSE file for details.

Author

Federico Sidraschi
LinkedIn | GitHub

Acknowledgments

Built with ezdxf - the excellent DXF library for Python.


Keywords: DXF, CAD, AutoCAD, marking, automation, batch processing, manufacturing, CNC, CAM

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

snapmark-2.0.1.tar.gz (32.0 kB view details)

Uploaded Source

Built Distribution

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

snapmark-2.0.1-py3-none-any.whl (35.8 kB view details)

Uploaded Python 3

File details

Details for the file snapmark-2.0.1.tar.gz.

File metadata

  • Download URL: snapmark-2.0.1.tar.gz
  • Upload date:
  • Size: 32.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for snapmark-2.0.1.tar.gz
Algorithm Hash digest
SHA256 65754426d1a30f40781d0433be36f8635b113829dff4820fa19dc3a09dba995b
MD5 834e9d031d2b78d4ff97d5f75028540f
BLAKE2b-256 796fb60f96c1e70a7b858f2538f94f09afd143163749e0524fddcaa6fd9eb18a

See more details on using hashes here.

File details

Details for the file snapmark-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: snapmark-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 35.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for snapmark-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cfd465251d2bd2be553e989b06c84a7b18845e299b1db789c65ccabc00fdd4e3
MD5 f6d2f855016ce159962f85b9067b264a
BLAKE2b-256 2e1119202c9689b4c3ac2c9ca8b8ba4f7288c6a871227564f81017401a1e10aa

See more details on using hashes here.

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