Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

dxf2vtk.py #enhancement #625

Closed
ahinoamp opened this issue Jan 6, 2020 · 3 comments
Closed

dxf2vtk.py #enhancement #625

ahinoamp opened this issue Jan 6, 2020 · 3 comments

Comments

@ahinoamp
Copy link

ahinoamp commented Jan 6, 2020

Hi,

Thank you so much for this wonderful package.
I'm using it in my workflow and very grateful for its existence.

I'm not sure how high the demand is for dxf converters, but there is certainly no easily found dxf converter online. Perhaps it would be a nice enhancement to your package. It can be done by uniting forces with the also excellent ezdxf package (which has a reader but no converter). Here is some initial thought:

import numpy as np
import meshio
import ezdxf
import pandas as pd

filename = 'input.dxf'
doc = ezdxf.readfile(filename)
msp = doc.modelspace()
faces = msp.query('3DFACE')
num3Dfaces=len(faces)
points = np.zeros((num3Dfaces*3, 3))
cells = np.zeros((num3Dfaces, 3),dtype ='int')
cell_data=[]

i=0
faceCounter=0
name = []
for e in faces:
    points[i, 0] = e.dxf.vtx0[0]
    points[i, 1] = e.dxf.vtx0[1]
    points[i, 2] = e.dxf.vtx0[2]

    points[i+1, 0] = e.dxf.vtx1[0]
    points[i+1, 1] = e.dxf.vtx1[1]
    points[i+1, 2] = e.dxf.vtx1[2]

    points[i+2, 0] = e.dxf.vtx2[0]
    points[i+2, 1] = e.dxf.vtx2[1]
    points[i+2, 2] = e.dxf.vtx2[2]

    cells[faceCounter,:]= [i, i+1, i+2]
    cell_data.append(e.dxf.layer)
    i=i+3
    faceCounter=faceCounter+1

meshio.write_points_cells(
    "foo.vtk",
    points,
    cells={'triangle':cells}   
    )

Happy new year,

Noe

@nschloe
Copy link
Owner

nschloe commented Sep 7, 2020

DXF is not a mesh format and hence not suitable for meshio.

@nschloe nschloe closed this as completed Sep 7, 2020
@brunorpinho
Copy link

@nschloe there are DXF entities that represents meshes. What @ahinoamp script is doing is extracting one of those entities ('3DFACE') from the DXF file and dumping into meshio. I recommend reading the DXF Reference document by AutoDesk and learning about those entities (3DFACE, SURFACE, MESH, POLYFACE MESH, 3D SOLID - this might be able to be converted to an unstructured grid).

I understand DXF has a lot of versions and all that is quite messy to deal with, but meshio could provide a way to extract only those entities. DXFs are used as a "mesh format" on a couple industries like mining.

@hjia1005
Copy link

@ahinoamp Your code helps a lot. It helps convert all our mine pits in the dxf format to vtk. Thanks.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

4 participants