abey79 / vpype

The Swiss-Army-knife command-line tool for plotter vector graphics.
https://vpype.readthedocs.io/
MIT License
690 stars 61 forks source link

How can you center a geometry on the document before writing #175

Closed theomega closed 3 years ago

theomega commented 3 years ago

Lets assume I have the following svg as input: https://gist.github.com/64f4bff934c9059e642806bfe625a03e

How can I center the actual geometry on an A4 paper in landscape before using write. Reason for not using write is that I actually want to use the output in the vype-gcode plugin.

I tried the following: vpype read LabradorLowPoly.svg pagesize --landscape a4 scaleto 29cm 19cm frame show -g --unit mm

Which leads to: Screenshot from 2021-01-25 16-12-02

Not bad, at least the size matches now, but how can I center this on the page? I checked translate but I ran into two issues: a) I don't know how to provide negative offsets b) I would not know which offsets to provide

What am I missing?

theomega commented 3 years ago

I found out how to provide negative values, it is super hacky though. The problem is you need to prevent click from interpreting the minus sign as a start of a cmd line parameter. You need to quote the number and add a space before the minus sign.

vpype read LabradorLowPoly.svg  pagesize --landscape a4 scaleto 30cm 20cm translate ' -10cm' ' -3cm' frame show -g --unit mm
abey79 commented 3 years ago

You put the finger right on vpype's missing piece.

First, for translate (standard Unix way to deal with this): translate -- -10cm -3cm. The -- notation means "end of options" so what follows is not interpreted as option even though it starts with -.

Then, a new layout command will address this issue more elegantly than write --center, which has many shortcomings as you rightly noticed. See #168. I'm hoping to release vpype with this addition in a matter of days. In the mean time, if you installed with pip you can get it from master:

pip install -U git+https://github.com/abey79/vpype#egg=vpype

If you used the installer, you can download one made from master here: https://github.com/abey79/vpype/suites/1894012677/artifacts/37071956

abey79 commented 3 years ago

Side note: if you havent already, consider joining the drawingbots discord server. I'm very often online and available for casual help.

https://drawingbots.net https://discord.com/invite/XHP3dBg

theomega commented 3 years ago

Great, that new branch worked perfectly! Thanks