Skip to content

optimise svg and dxf exports #1169

Open
@njourdane

Description

@njourdane

Here is a basic script that produce a rounded box:

import cadquery as cq
from cadquery import exporters

result = ( cq
    .Workplane('XY')
    .box(50, 50, 1)
    .edges('|Z')
    .fillet(10)
)

exporters.export(result, 'test.svg', opt={
    'width': 300,
    'height': 300,
    'marginLeft': 10,
    'marginTop': 10,
    'showAxes': False,
    'projectionDir': (0, 0, 1),
    'strokeWidth': 0.1,
    'strokeColor': (0, 0, 0),
    'hiddenColor': (0, 0, 255),
    'showHidden': False
})

Only one path is necessary for 2d export, but if we look at the source, we can see that many paths are created:

       <g  stroke="rgb(0,0,0)" fill="none">
			<path d="..." />
			<path d="..." />
			<path d="..." />
			<path d="..." />
			<path d="..." />
			<path d="..." />
			<path d="..." />
			<path d="..." />
       </g>

This can be very annoying when using a cnc or laser cutter, because the tool will make a lot of additional useless movements and wille take much more time to cut the piece.

Here is a simulation of what a machine will do on the exported svg (svg moves are replaced with lines):
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    dxfquestionFurther information is requestedsvg

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions