CadQuery / CadQuery/cadquery

svg export: ability to define the camera position and zoom

Open
#730 2 comments 0 reactions 0 assignees View on GitHub
svg
Dominant language
Python
Stars
5.8k
Forks
541
Avg merge
3d 2h
Merged PRs (30d)
5

Description

Let's start with this code:

```py
import cadquery as cq
from cadquery.cq import Workplane as WP

def fig(wp):
cube1 = WP(wp).box(5, 5, 5)
rod1 = WP(wp).circle(1).extrude(15)
return cube1.union(rod1)

svg_opts = {'height': 100, 'showHidden': False, 'showAxes': False}
cq.exporters.export(fig('XY'), 'fig1.svg', opt=svg_opts)
cq.exporters.export(fig('XZ'), 'fig2.svg', opt=svg_opts)
```

![image](https://user-images.githubusercontent.com/1665542/115015857-95d50680-9eb4-11eb-9efb-c7bbb344645b.png)![image](https://user-images.githubusercontent.com/1665542/115015804-85bd2700-9eb4-11eb-9834-699a472c5671.png)

These images share the same height. But what I need is to have the same box size and position. So instead of defining svg `width` and `height` in svg export options, I would like to set the camera position and zoom.

My current hack is to add a "background plate", like this:

```py
bg = WP('ZX').transformed(offset=V(-3, 0, -5)).box(1, 17, 25)`)
```

![image](https://user-images.githubusercontent.com/1665542/115017168-61fae080-9eb6-11eb-9a1a-260d43eff33d.png)![image](https://user-images.githubusercontent.com/1665542/115017196-6de6a280-9eb6-11eb-8c69-0dcaaed0b3f9.png)

Then I remove this plate by editing the svg in Inkscape. But it's a little bit tedious.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.