In this post we present a script written in python to create a DXF from a text file with ID and X Y Z points.
The script utilizes the ezdxf library. Ezdxf is a Python interface to the DXF (drawing interchange file) format developed by Autodesk, ezdxf allows developers to read and modify existing DXF documents or create new DXF documents.
See the code below. It is straightforward to create the DXF with just a double click on the script. The text file must contain space-delimited list of 3d points (ID X Y Z).
import ezdxf from ezdxf.enums import TextEntityAlignment from ezdxf.gfxattribs import GfxAttribs # Open the text file and read the lines with open('xyz.txt', 'r') as file: lines = file.readlines() doc = ezdxf.new("R2000") msp = doc.modelspace() attribsp = GfxAttribs(layer="GPS") attribst = GfxAttribs(layer="GPS-text") # Loop through the lines and extract the id and point coordinates for line in lines: parts = line.split() id = parts x = float(parts) y = float(parts) z = float(parts) msp.add_point((x, y, z), dxfattribs=attribsp) msp.add_text(id,height=0.5,dxfattribs=attribst).set_placement( (x, y, z), align=TextEntityAlignment.LEFT) # Save the DXF file doc.saveas('points.dxf')