abey79 / vsketch

Generative plotter art environment for Python
https://vsketch.readthedocs.io/en/latest/
Other
492 stars 50 forks source link

Add the capability to load a SVG in a sketch #41

Open abey79 opened 3 years ago

abey79 commented 3 years ago

API:

zumpchke commented 3 years ago

+1. I tried this vsk.vpype("read path/to/sketch.svg")

It works, but I can't translate the sketch?

abey79 commented 3 years ago

@zumpchke I'm sorry I somehow failed to see and answer to your message until now.

Indeed the transforms in vsketch apply to future drawings, and vsk.vpype() acts at a lower level which is not affected by vsketch transforms. This is why this work-around is less than optimal. In order to translate/scale the input svg, you will need to do it inside the vsk.vpype() call, e.g.:

vsk.vpype("read path/to/sketch.svg scaleto 10cm 10cm translate 2cm 2cm")

See the doc of scale, scaleto and translate for details.

abey79 commented 2 years ago

Another, better work-around with subsketch:

# load SVG into a sub-sketch
sub = vsketch.Vsketch()
sub.vpype(f"read {file_path}")

# draw the sub-sketch into the main sketch, applying any transformation which may be set
with vsk.resetMatrix():
    vsk.scale(0.5)  # scale the SVG
    vsk.translate(X, Y)  # translate the SVG
    vsk.sketch(sub)
abey79 commented 1 year ago

Another work-around consists of using vpype.read_svg() and friends.