Skip to content

Latest commit

 

History

History
166 lines (129 loc) · 4.47 KB

README.org

File metadata and controls

166 lines (129 loc) · 4.47 KB

svg_to_scad.py

Features

  • Allows fine-grained control over the number of samples for Bezier curves and arcs
  • Capability to output the results into a JSON file or a SCAD file wrapped into a polygon module.
  • Scaling, flipping, rotating, moving capabilities.
  • Display graph to visualize the generated result
  • Output final result dimensions

Usage

SVG demo files

demo/straight_lines_svg_rendering.png

demo/bezier_curves_svg_rendering.png

Input and output options

python svg_to_scad.py --input demo/straight_lines.svg --output demo/straight_lines.json
Width: 60.292721
Height: 83.38827
Coordinates saved to demo/straight_lines.json

Graph:

demo/fig_svg_to_scad_straight_lines_graph.png

Close option

python svg_to_scad.py -i demo/straight_lines.svg -o demo/straight_lines.json --close
Width: 60.292721
Height: 83.38827
Coordinates saved to demo/straight_lines.json

Graph:

demo/fig_svg_to_scad_straight_lines_graph_close.png

Sampling option

python svg_to_scad.py -i demo/bezier_curves.svg -o demo/bezier_curves.scad --number-samples 10
Width: 141.81590968696838
Height: 99.41870528120708
Coordinates saved to demo/bezier_curves.scad

Graph:

demo/fig_svg_to_scad_bezier_curves_number_samples.png

Center of gravity

python svg_to_scad.py -i demo/bezier_curves.svg -o demo/bezier_curves.scad -n 15 --center-of-gravity
Width: 141.8418028987973
Height: 99.69069757835271
Coordinates saved to demo/bezier_curves.scad

Graph:

demo/fig_svg_to_scad_bezier_curves_center_of_gravity.png

help menu

For a complete list of options, consult the help menu:

python svg_to_scad.py --help
usage: svg_to_scad.py [-h] -i INPUT [-n NUMBER_SAMPLES] [-o OUTPUT] [-c]
                      [-f {x,y}] [-s SCALE] [-r ROTATE] [-g] [-C]

Convert SVG paths to a list of coordinates for use in OpenSCAD.

options:
  -h, --help            show this help message and exit
  -i, --input INPUT     Path to the SVG file.
  -n, --number-samples NUMBER_SAMPLES
                        Number of samples for Bezier curves and arcs (default:
                        100).
  -o, --output OUTPUT   Output file name (default: coordinates.scad).
  -c, --close           Close the path by adding the first point to the end if
                        not already closed.
  -f, --flip {x,y}      Flip the coordinates either horizontally or
                        vertically.
  -s, --scale SCALE     Scale the coordinates. Format: x:y, x:, or :y
  -r, --rotate ROTATE   Rotate the coordinates by the specified angle (in
                        degrees).
  -g, --center-of-gravity
                        Center the coordinates at the center of gravity of the
                        shape.
  -C, --center          Center the shape at the origin based on the bounding
                        rectangle.

Usage in OpenSCAD

// Load the generated SCAD files
use <straight_lines.scad>
use <bezier_curves.scad>

// Use the polygon modules defined in the included files
translate([-200, -40, 0]) {
    linear_extrude(10)
    straight_lines();
}

translate([-100, -100, 0]) {
    linear_extrude(15)
    bezier_curves();
}

demo/import_coordonate_files_demo.png