Open abey79 opened 3 years ago
+1.
I tried this
vsk.vpype("read path/to/sketch.svg")
It works, but I can't translate the sketch?
@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")
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)
Another work-around consists of using vpype.read_svg()
and friends.
API:
vsketch.Vsketch(input.svg, merge=True/False)
: initialise the sketch with the SVG's dimensions and content, optionally merging all SVG layers into a single one.vsk.image(input.svg)
: inserts the SVG in the sketch, applying any transforms and/or fill