Importing DXF with bend line fails

30 views
Skip to first unread message

Joel Bäckström

unread,
Apr 28, 2024, 5:54:27 AMApr 28
to CadQuery
Hey! I'm trying to import a .dxf into a cadquery workplane using cq.importers.importDXF but get a "ValueError: Cannot build face(s): wires not planar" which I'm guessing is because there is a bend line on the sheet.

Should this be possible to import using the importDXF function? And if not, what options do I have to reading files like this? 

Adding a sample .dxf file as an attachment.
sheet-with-bend-line.dxf

Adam Urbanczyk

unread,
Apr 28, 2024, 11:12:07 AMApr 28
to CadQuery
DXF import is indeed limited to planar objects. If you need something 3D, try STEP.

Joel Bäckström

unread,
Apr 28, 2024, 11:41:02 AMApr 28
to CadQuery
Yeah, we use STEP for some stuff as well. The problem here is that the files are provided to me in a given format, most cases DXF. 

How come other CAD-software supports it? 

Adam Urbanczyk

unread,
Apr 28, 2024, 12:03:46 PMApr 28
to CadQuery
You are free to implement a plugin that does what you need and share it with the community. In the meantime your best bet is to convert your DXFs to STEP and import that.

Jeremy Wright

unread,
Apr 29, 2024, 8:14:37 AMApr 29
to Adam Urbanczyk, CadQuery
ezdxf is one of CadQuery's dependencies and can be used to pre-process DXF files. So you can remove the entities from the bend line layer so that the rest can be imported properly.

import cadquery as cq
from cadquery.vis import show
import ezdxf

def preprocess_dxf(input_dxf_path, layer_name):
"""
Removes bend and center lines from the DXF.
"""

# Read the original DXF file in
dxf = ezdxf.readfile("sheet-with-bend-line.dxf")

# Remove all entities from the layer, turning the layer off
# and/or deleting the layer definition is not enough
with dxf.entitydb.trashcan() as trash:
for entity in dxf.entitydb.values():
if not entity.dxf.hasattr("layer"):
continue
if layer_name == entity.dxf.layer:
# safe destruction while iterating
trash.add(entity.dxf.handle)

# Output the modified DXF as a copy
output_filename = input_dxf_path.replace(".dxf", "-copy.dxf")
dxf.saveas(output_filename)

return output_filename

# Work with the cleaned-up DXF
dxf_output_name = preprocess_dxf("sheet-with-bend-line.dxf", "DOWN_CENTERLINES")
bar = cq.importers.importDXF(dxf_output_name)

# The following line works to convert the wires into something that can be extruded.
# In the example, it ends up being a bar with pairs of holes down the x-axis.
# bar = bar.wires().toPending().extrude(10.0)

show(bar)

--
cadquery home: https://github.com/CadQuery/cadquery
post issues at https://github.com/CadQuery/cadquery/issues
run it at home at : https://github.com/CadQuery/CQ-editor
---
You received this message because you are subscribed to the Google Groups "CadQuery" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cadquery+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cadquery/a50393aa-6195-42ed-8ccf-53994d4498c1n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages