Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion cadquery/occ_impl/exporters/dxf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from OCP.GeomConvert import GeomConvert
from OCP.gp import gp_Dir
from OCP.GC import GC_MakeArcOfEllipse
from OCP.TopAbs import TopAbs_Orientation
from typing_extensions import Self

from ...cq import Face, Plane, Workplane
Expand Down Expand Up @@ -199,9 +200,17 @@ def _dxf_line(edge: Edge) -> DxfEntityAttributes:

:return: dictionary of DXF entity attributes for creating a line
"""

if edge.wrapped.Orientation() == TopAbs_Orientation.TopAbs_FORWARD:
start = edge.startPoint()
end = edge.endPoint()
else:
start = edge.endPoint()
end = edge.startPoint()

return (
"LINE",
{"start": edge.startPoint().toTuple(), "end": edge.endPoint().toTuple(),},
{"start": start.toTuple(), "end": end.toTuple(),},
)

@staticmethod
Expand Down
18 changes: 18 additions & 0 deletions tests/test_exporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -942,3 +942,21 @@ def test_dxf_ellipse_arc(tmpdir):

assert w2.val().isValid()
assert w2.val().Volume() == approx(math.pi * r ** 2 / 4)


def test_dxf_edge_iteration(tmpdir):

w1 = Workplane().box(50, 50, 1).edges("|Z and >XY").fillet(10)

dxf = exporters.dxf.DxfDocument()
dxf.add_layer("layer1", color=1)
dxf.add_shape(w1.section(0), "layer1")

fname = tmpdir.joinpath("edge_iteration1.dxf").resolve()
dxf.document.saveas(fname)

s1 = Sketch().importDXF(fname)
edges = s1.edges().vals()

for e1, e2 in zip(edges, edges[1:]):
assert (e2.startPoint() - e1.endPoint()).Length == approx(0.0)