Created combine_svg_vertical.py to vertically stack SVG files with centering
and configurable spacing. Enhanced svg_logo_to_stl.py with plate dimensions
and margin options for better nameplate creation.
combine_svg_vertical.py features:
- Vertically combines two SVG files (icon above text)
- Automatically centers smaller element
- Configurable spacing between elements (default: 20px)
- Configurable margin around composition (default: 10px)
- Preserves individual SVG structure in groups
svg_logo_to_stl.py enhancements:
- Added --plate-width and --plate-height options
- Logo scales to fit within plate dimensions (maintaining aspect ratio)
- Added --margin option for spacing around logo on plate
- Automatic centering of logo on plate
- Reports actual dimensions: plate, logo, margin, and offset
Example usage:
# Combine icon and text
python combine_svg_vertical.py um_grey.svg um_black.svg combined.svg --spacing 114
# Center on 256x256mm plate with 10mm margin
python svg_logo_to_stl.py combined.svg output \
--plate-width 256 --plate-height 256 --margin 10 \
--base-thickness 1.5 --feature-height 2.5
Files:
- combine_svg_vertical.py: Vertical SVG stacking tool
- README_combine_svg.md: Documentation for combine tool
- underground-magnetics-combined.svg: Example combined logo
- svg_logo_to_stl.py: Enhanced with plate dimensions
- command.txt: Updated with new parameters
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
113 lines
3.3 KiB
Markdown
113 lines
3.3 KiB
Markdown
# Combine SVG Vertical
|
||
|
||
A script to combine two SVG files vertically with automatic centering and configurable spacing.
|
||
|
||
## Purpose
|
||
|
||
This tool is designed for preparing multi-part logos for 3D printing by:
|
||
- Placing an icon/logo above text
|
||
- Automatically centering the smaller element
|
||
- Adding configurable spacing between elements
|
||
- Maintaining proper dimensions for STL conversion
|
||
|
||
## Usage
|
||
|
||
```bash
|
||
python combine_svg_vertical.py <top_svg> <bottom_svg> <output_svg> [options]
|
||
```
|
||
|
||
### Arguments
|
||
|
||
- `top` - Top SVG file (e.g., icon or logo)
|
||
- `bottom` - Bottom SVG file (e.g., text)
|
||
- `output` - Output combined SVG file
|
||
|
||
### Options
|
||
|
||
- `--spacing, -s` - Vertical spacing between elements in pixels (default: 20)
|
||
- `--margin, -m` - Margin around entire composition in pixels (default: 10)
|
||
|
||
## Examples
|
||
|
||
### Basic Usage (Underground Magnetics Logo)
|
||
```bash
|
||
python combine_svg_vertical.py um_grey.svg um_black.svg underground-magnetics-combined.svg
|
||
```
|
||
|
||
**Result:**
|
||
- Grey "UM" icon (413×390) centered above black text (3070×233)
|
||
- 20px spacing between icon and text
|
||
- 10px margin around composition
|
||
- Final canvas: 3090×663px
|
||
|
||
### Custom Spacing
|
||
```bash
|
||
# Larger spacing between elements
|
||
python combine_svg_vertical.py icon.svg text.svg combined.svg --spacing 50
|
||
|
||
# Larger margin around composition
|
||
python combine_svg_vertical.py icon.svg text.svg combined.svg --margin 30
|
||
|
||
# Both custom
|
||
python combine_svg_vertical.py icon.svg text.svg combined.svg -s 40 -m 20
|
||
```
|
||
|
||
## How It Works
|
||
|
||
1. **Load SVGs** - Reads dimensions from viewBox or width/height attributes
|
||
2. **Calculate Layout** - Determines positioning based on:
|
||
- Maximum width of both elements
|
||
- Combined height + spacing
|
||
- Centering offsets for smaller element
|
||
3. **Create Groups** - Wraps each SVG in a `<g>` group with transform
|
||
4. **Combine** - Creates new SVG canvas with both elements positioned
|
||
|
||
## Output Structure
|
||
|
||
```xml
|
||
<svg width="..." height="..." viewBox="...">
|
||
<!-- Combined: top.svg (top) + bottom.svg (bottom) -->
|
||
<g id="top" transform="translate(x_offset, y_offset)">
|
||
<!-- All elements from top SVG -->
|
||
</g>
|
||
<g id="bottom" transform="translate(x_offset, y_offset)">
|
||
<!-- All elements from bottom SVG -->
|
||
</g>
|
||
</svg>
|
||
```
|
||
|
||
## Integration with 3D Workflow
|
||
|
||
After combining SVGs, you can convert to STL:
|
||
|
||
```bash
|
||
# Convert combined logo to 3D model
|
||
python svg_logo_to_stl.py underground-magnetics-combined.svg um_logo \
|
||
--width-mm 100 \
|
||
--base-thickness 1.5 \
|
||
--feature-height 2.5
|
||
```
|
||
|
||
This will create a single 3D model with both the icon and text at the same height (not stacked vertically in 3D, just in the 2D layout).
|
||
|
||
## Tips
|
||
|
||
- **Spacing**: Use `--spacing` to adjust the gap between icon and text
|
||
- Small spacing (10-20): Compact look
|
||
- Medium spacing (20-40): Balanced (default)
|
||
- Large spacing (50+): Separated elements
|
||
|
||
- **Margin**: Use `--margin` to add breathing room around the entire composition
|
||
- Useful when the combined SVG will be cropped or bounded
|
||
|
||
- **Order Matters**: The first argument is always placed on top
|
||
- Icon above text: `combine_svg_vertical.py icon.svg text.svg ...`
|
||
- Text above icon: `combine_svg_vertical.py text.svg icon.svg ...`
|
||
|
||
## File Size
|
||
|
||
The combined SVG file size is approximately the sum of the input files:
|
||
- um_grey.svg: 728B
|
||
- um_black.svg: 6.1KB
|
||
- **Combined**: 7.0KB
|