Skip to content

svg export: ability to define the camera position and zoom #730

@njourdane

Description

@njourdane

Let's start with this code:

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)

imageimage

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:

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

imageimage

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions