Reading a drawing file
The digi21.io package reads Digi3D.AI drawing files. One module per format, all with the same interface: open returns an iterable DrawingFile.
| Module | Format |
|---|---|
digi21.io.bindouble |
BinDouble (.bind) |
digi21.io.bin |
Bin (.bin) |
digi21.io.asciidigi |
ASCII Digi (.asc) |
digi21.io.dgn |
MicroStation DGN (.dgn) |
digi21.io.dwg |
AutoCAD DWG (.dwg) |
digi21.io.dxf |
AutoCAD DXF (.dxf) |
This topic uses these six modules. Other formats (GeoJSON, KML, SVG, WKT, GeoPackage, SHP, GeoMedia, PostGIS, IFC and VEC) are read the same way; each module's page in digi21.io has a reading example.
Opening and iterating
import digi21.io.bindouble as bind
drawing = bind.open("ciudad.bind")
for geometry in drawing:
print(type(geometry).__name__, len(geometry), "vértices")
Iteration is lazy: geometries are read from the file as you iterate.
Counting geometries by type
import collections
import digi21.io.dgn as dgn
conteo = collections.Counter()
for geometry in dgn.open("hoja.dgn"):
conteo[type(geometry).__name__] += 1
for tipo, n in conteo.items():
print(f"{tipo}: {n}")
Filtering by type and code
import digi21.io.dxf as dxf
from digi21.base import Line
for geometry in dxf.open("planta.dxf"):
if isinstance(geometry, Line) and geometry.closed:
if any(c.matches("EDIF*") for c in geometry.codes):
print("Edificio cerrado con", len(geometry), "vértices")
Using a codes table
Passing a DigiTab supplies descriptions, visibility and other code properties for the geometries read:
import digi21.base as base
import digi21.io.bindouble as bind
digitab = base.DigiTab.load("Digi.tab.xml")
drawing = bind.open("ciudad.bind", digitab=digitab)
for geometry in drawing:
for code in geometry.codes:
print(code.code)