Skip to content

ArnavBhalla/Forge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Forge - Mechanical Part Generator

A proof-of-concept tool that converts natural language descriptions of mechanical parts into valid OpenSCAD code.

Current Status: Step 4 - Multiple Bracket Types ✓

The tool now supports three bracket types: L-brackets, flat plates, and 3-way corner brackets!

Installation

# Install dependencies
pip3 install anthropic

# Set your API key
export ANTHROPIC_API_KEY='your-api-key-here'

Get your API key at: https://console.anthropic.com/

Usage

Option 1: Natural Language (with API key)

python3 bracket_gen.py

Then describe your bracket in natural language:

Description: L-bracket, 60mm wide, 80mm tall, M4 holes
Description: Flat mounting plate, 80x60mm, 4 corner holes
Description: Corner bracket for 3 surfaces, 60mm size

The tool will:

  1. Detect the bracket type from your description
  2. Parse dimensions and parameters with Claude
  3. Ask clarifying questions for missing details
  4. Validate the design
  5. Generate the OpenSCAD file

Option 2: Test Examples (no API key needed)

python3 test_example.py       # Original L-bracket tests
python3 test_all_brackets.py   # All bracket types (11 variants)

This generates example brackets of all types to demonstrate functionality.

Supported Bracket Types

1. L-Bracket (Right-Angle)

Two perpendicular flanges at 90 degrees:

  • Base: Configurable width × depth × thickness
  • Vertical flange: Configurable height × thickness
  • Mounting holes: 2-4 on base, 0-N on vertical
  • Corner fillet: For structural strength
  • Use cases: Wall mounting, shelf brackets, equipment mounting

2. Flat Plate (Mounting Plate)

Single flat plate with flexible hole patterns:

  • Dimensions: Configurable width × depth × thickness
  • Hole patterns: Corners, grid, edge, or center
  • Corner fillets: Optional (for rounded corners)
  • Use cases: Adapter plates, mounting bases, spacers

3. Corner Bracket (3-Way)

Three-way bracket for internal corners:

  • Size: Equal-sized flanges on all three planes
  • Mounting holes: 2-4 per flange
  • Fillets: Cylindrical + spherical at junction
  • Use cases: Frame corners, box assembly, shelf supports

See BRACKET_TYPES.md for complete details on all bracket types.

Viewing the Output

  1. Install OpenSCAD
  2. Open the generated .scad file
  3. Press F5 to preview or F6 to render
  4. Export as STL via File → Export → Export as STL

Example Workflow

$ python3 bracket_gen.py

Description: I need a 50mm wide, 70mm tall L-bracket with M4 holes

PROCESSING WITH CLAUDE
========================
Confidence: HIGH
Interpretation: L-bracket with 50mm base width, 70mm vertical height,
M4 mounting holes (5mm clearance)

CLARIFICATION NEEDED
====================
The following details need clarification:

1. Base thickness not specified (affects structural strength)
2. Number of mounting holes on base (2 or 4)
3. Number of holes on vertical flange

Base Thickness [3mm]:
Fillet Radius [5mm]:
Hole Diameter [5mm]:
Base Hole Count [4]:
Vert Hole Count [2]:

Use square base (50mm x 50mm)? [Y/n]:

✓ Generated: l_bracket_50x70.scad
✓ File size: 1242 bytes

Generated OpenSCAD Code

The script produces clean, well-commented OpenSCAD:

// L-Bracket Generated by Forge
// Dimensions: 50mm x 50mm base, 70mm height
// Designed for 3D printing with PLA/PETG

$fn = 50; // Circle resolution

module l_bracket() {
    difference() {
        union() {
            // Base (horizontal flange)
            cube([50, 50, 3]);

            // Vertical flange
            translate([0, 0, 3])
                cube([50, 3, 70]);

            // Corner fillet for strength
            translate([0, 3, 3])
                rotate([0, 90, 0])
                cylinder(r=5, h=50);
        }

        // Subtract mounting holes from base
        translate([10, 10, -5.0])
            cylinder(d=5, h=13);
        // ... more holes ...
    }
}

l_bracket();

Features (Step 4 Complete)

  • Natural language input parsing via Claude AI
  • Automatic bracket type detection (L-bracket, flat plate, corner bracket)
  • ✓ Dynamic dimension extraction from descriptions
  • ✓ Interactive parameter refinement with sensible defaults
  • ✓ Support for multiple screw sizes (M3, M4, M5, M6)
  • Multiple bracket types:
    • L-brackets (right-angle, 2 flanges)
    • Flat plates (single plane, various hole patterns)
    • Corner brackets (3-way, internal corners)
  • Flexible hole patterns (corners, grid, edge, center)
  • ✓ Configurable hole counts (2-4 base holes, 0-N vertical holes)
  • ✓ Automatic fillet generation for structural strength
  • ✓ Clean, commented OpenSCAD output
  • ✓ Material hints in comments
  • Comprehensive parameter validation
    • Dimension sanity checks (min/max, positive values)
    • Hole overlap detection
    • Edge clearance validation
    • Geometry consistency checks
  • OpenSCAD syntax validation (if OpenSCAD installed)
  • Detailed error messages with actionable feedback
  • Extensible architecture (easy to add new bracket types)

Known Limitations (Step 4)

  • ✗ Fixed hole positioning for L-brackets (10mm from edges)
  • ✗ No preview/visualization within the tool
  • ✗ Requires OpenSCAD for viewing/rendering
  • ✗ Limited bracket types (3 types currently)
  • ✗ No T-brackets, hinges, or custom geometries yet

Completed Steps

  • Step 1: Hardcoded L-bracket generation
  • Step 2: LLM integration with Claude API
  • Step 3: Comprehensive validation layer
  • Step 4: Multiple bracket types (L-bracket, flat plate, corner bracket)

Next Steps

Step 5: Enhanced Features (Priority: Medium)

  • T-brackets
  • U-channel brackets
  • Custom hole patterns (user-defined positions)
  • Configurable hole spacing/offset

Step 6: Advanced Features (Priority: Low)

  • Support for countersunk holes
  • Lightening pockets (material reduction)
  • Text embossing (labels, version numbers)
  • Multiple material presets with optimized settings

Project Structure

Forge/
├── bracket_gen.py              # Main generator (LLM-powered, multi-type)
├── generators.py               # Bracket type generators module
├── validator.py                # Validation module
├── test_example.py             # Original L-bracket tests
├── test_all_brackets.py        # Multi-bracket test suite (11 variants)
├── test_validation.py          # Validation test suite
├── README.md                   # This file
├── USAGE.md                    # Detailed usage guide
├── VALIDATION.md               # Validation reference
├── BRACKET_TYPES.md            # Bracket types reference
├── QUICKSTART.md               # Quick reference
├── *.scad                      # Generated OpenSCAD files
└── test_*.scad                 # Test outputs (L-brackets, plates, corners)

Design Decisions

  1. Pure OpenSCAD output: No custom geometry kernel needed
  2. Simple primitives: Uses only cube(), cylinder(), translate(), rotate()
  3. Readable code: Generated SCAD files include comments and consistent formatting
  4. Fillet approach: Uses cylindrical fillets for strength (could be enhanced with hull())

Testing Checklist

Code Generation

  • Script runs without errors
  • Generates valid .scad files
  • Parameterized generation works
  • Multiple test cases pass
  • OpenSCAD renders without errors (requires manual testing)
  • STL export works (requires manual testing)
  • Part is 3D printable (requires actual printing test)

LLM Integration

  • API key validation works
  • Natural language parsing extracts dimensions correctly (needs live testing)
  • Clarification questions are relevant (needs live testing)
  • Default values are sensible
  • Edge cases handled (missing dimensions, invalid input)

Validation (Step 3)

  • Dimension validation works (13/13 tests passed)
  • Hole overlap detection works
  • Edge clearance validation works
  • Negative value detection works
  • Zero dimension detection works
  • Geometry consistency checks work
  • OpenSCAD syntax validation works (when OpenSCAD installed)
  • Error messages are clear and actionable
  • Warnings vs. errors are properly categorized

Evaluation Criteria

  1. Valid OpenSCAD code: Can it be rendered?
  2. Usability: Could a non-CAD-expert use the output?
  3. Quality: Is the output 3D printable?
  4. Correctness: Do dimensions match specifications?

Example Natural Language Inputs

The tool can understand various phrasings for all bracket types:

L-Brackets

  • "I need a 60mm wide, 80mm tall L-bracket with M4 holes"
  • "Make me a right-angle bracket, 50x70mm with 4 mounting holes"
  • "L-bracket for mounting a motor, 100mm base, 120mm height, M6 bolts"
  • "Small bracket 40mm square base, 50mm vertical, M3 screws"

Flat Plates

  • "Flat mounting plate, 80x60mm, 4 corner holes"
  • "Adapter plate, 100mm square, grid pattern with 9 holes"
  • "Mounting base, 70x50mm, M5 holes at edges"
  • "Spacer plate with rounded corners, 60mm, 4 holes"

Corner Brackets

  • "Corner bracket for joining 3 surfaces, 60mm"
  • "3-way bracket, 80mm, M6 holes"
  • "Box corner reinforcement, 50mm size"
  • "Internal corner bracket, 100mm, heavy duty"

API Usage Note

The tool uses Claude Sonnet 4.5 for natural language processing. Typical costs:

  • Input: 200 tokens per description ($0.0006)
  • Output: 100-200 tokens ($0.0015)
  • Total per bracket: ~$0.002 (less than 1 cent)

Status: Step 4 complete. Multiple bracket types implemented (L-bracket, flat plate, corner bracket). Next: Enhanced features and more bracket types.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages