Skip to content

Commit 2d721d0

Browse files
add the choice to not import all dxf layers (#442)
* add the choice to not import all dxf layers this is especially useful for ignoring layers in drawings containing note text or dimensions * remove a blank line * Rework layer exclusion in dxf import * add dxf for layer tests * add tests for dxf import layer filtering and extrusion fix edges/wires mixup remove extra `)` fix var name typo fix lint Co-authored-by: Adam Urbańczyk <adam-urbanczyk@users.noreply.github.com>
1 parent b3d089f commit 2d721d0

File tree

3 files changed

+14029
-2
lines changed

3 files changed

+14029
-2
lines changed

cadquery/occ_impl/importers.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -214,19 +214,20 @@ def _dxf_convert(elements, tol):
214214
return rv
215215

216216

217-
def importDXF(filename, tol=1e-6):
217+
def importDXF(filename, tol=1e-6, exclude=[]):
218218
"""
219219
Loads a DXF file into a cadquery Workplane.
220220
221221
:param fileName: The path and name of the DXF file to be imported
222222
:param tol: The tolerance used for merging edges into wires (default: 1e-6)
223+
:param exclude: a list of layer names not to import (default: [])
223224
"""
224225

225226
dxf = ezdxf.readfile(filename)
226227
faces = []
227228

228229
for name, layer in dxf.modelspace().groupby(dxfattrib="layer").items():
229-
res = _dxf_convert(layer, tol)
230+
res = _dxf_convert(layer, tol) if name not in exclude else None
230231
if res:
231232
wire_sets = sortWiresByBuildOrder(res)
232233
for wire_set in wire_sets:

tests/test_importers.py

+14
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,20 @@ def testImportDXF(self):
130130
self.assertTrue(obj.val().isValid())
131131
self.assertEqual(obj.faces().size(), 1)
132132

133+
# test layer filtering
134+
filename = os.path.join(testdataDir, "three_layers.dxf")
135+
obj = importers.importDXF(filename, exclude=["Layer2"])
136+
self.assertTrue(obj.val().isValid())
137+
self.assertEqual(obj.faces().size(), 2)
138+
self.assertEqual(obj.wires().size(), 2)
139+
140+
# test dxf extrusion into the third dimension
141+
extrusion_value = 15.0
142+
tmp = obj.wires()
143+
tmp.ctx.pendingWires = tmp.vals()
144+
threed = tmp.extrude(extrusion_value)
145+
self.assertEqual(threed.findSolid().BoundingBox().zlen, extrusion_value)
146+
133147

134148
if __name__ == "__main__":
135149
import unittest

0 commit comments

Comments
 (0)