The Drawing eXchange Format (DXF) is one of the most widely supported vector formats in Computer-Aided Design. It was developed with the purpose of enabling data interoperability between different CAD systems. The format is supported by many programs including MineSight, AutoCAD, Visio, and ArcMap.
DXF files can be used for storing many types of geometries. This module supports the reading and writing of labels, polylines, markers, and shells (solids/surfaces).
The following snippet illustrates how to read from a DXF file,
At this point the point_list and face_list contain the standard point and face lists as defined in the grail.ag module's Standard Definitions.
An example of writing geometry data to DXF is as follows,
open(path [,mode])
Opens a file at the given path. The mode can be either "r" for read-only, or "w" for write-only. If you want to create a new file use the "w" option (if the file exists, it will be overwritten). Mode is read-only by default.
If you are attempting to open a file in "r" mode and it does not exist, an IOError is generated.
DXF
Use the open function to load/create a DXF object. For the most part this object behaves as a regular file object in Python.
Methods
- addlabel(position, text, size, layername)
- Append a new label element to the file.
- addmarkers(point, layername)
- Append a new markers element to the file.
- addpolyline(point_list, layername)
- Append a new polyline to the file.
- addshell(point_list, face_list, layername)
- Append a new shell to the file.
- getlabelcount()
- Return the number of labels in the file.
- getlabelpositionat(idx)
- Return the label's position at the given index.
- getlabeltextat(idx)
- Return the label's text value at the given index.
- getlabelsizeat(idx)
- Return the label's size at the given index.
- getmarkerspointsat(idx)
- Return the markers points at the given index.
- getmarkerscount()
- Return the number of markers in the file.
- getmarkerspointsat(idx)
- Return the markers points at the given index.
- getpolylinecount()
- Return the number of polylines in the file.
- getpolylinepointsat(idx)
- Return the polyline points at the given index.
- getshellcount()
- Return the number of shells in the file.
- getshellpointsat(idx)
- Return the shell points at the given index.
- getshellfacesat(idx)
- Return the shell faces at the given index.
- close()
- This closes the file handle to the object. If you fail to close the file explicitly, the file will be closed implicitly when object falls out of scope.
Attributes
mode
Indicates the mode that the file is in. For example this would be "r" (read-only), or "w" (write-only).name
This is the path to the file.closed
Is True when the object has been closed.