I am trying to correctly extract vertices and faces from POLYLINE(POLYFACE) DXF files. When I try to create a Trimesh after extraction nothing is showing up. Any idea?
doc = ezdxf.readfile(r"C:\Users\Baldan\Downloads\simplified.dxf")
msp = doc.modelspace()
vertices = []
faces = []
for e in msp:
for vertex in e.vertices:
if vertex.is_face_record:
# Extract face information
indices = [vertex.get_dxf_attrib(name, 0) for name in ('vtx0', 'vtx1', 'vtx2', 'vtx3')]
# Filter out 0 indices as they indicate the end of the face definition
indices = [idx for idx in indices if idx != 0]
faces.append(tuple(indices))
# Assuming vertex is a DXFVertex with a .dxf.location attribute
x, y, z = vertex.dxf.location
vertices.append((x, y, z))
mesh = trimesh.Trimesh(vertices=vertices, faces=faces)
mesh.export('test.ply', file_type='ply')
You have to separate the face and location
VERTEXentities and for some unknown reason are the vertex indices 1-based: