1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
.. _iterdxf:
.. module:: ezdxf.addons.iterdxf
iterdxf
=======
This add-on allows iterating over entities of the modelspace of really big (> 5GB) DXF files which do not fit into
memory by only loading one entity at the time. Only ASCII DXF files are supported.
The entities are regular :class:`~ezdxf.entities.DXFGraphic` objects with access to all supported DXF attributes,
this entities can be written to new DXF files created by the :meth:`IterDXF.export` method.
The new :meth:`~ezdxf.layouts.BaseLayout.add_foreign_entity` method allows also to add this entities to
new regular `ezdxf` drawings (except for the INSERT entity), but resources like linetype and style are removed,
only layer will be preserved but only with default attributes like color ``7`` and linetype ``CONTINUOUS``.
The following example shows how to split a big DXF files into several separated DXF files which contains
only LINE, TEXT or POLYLINE entities.
.. code-block:: Python
from ezdxf.addons import iterdxf
doc = iterdxf.opendxf('big.dxf')
line_exporter = doc.export('line.dxf')
text_exporter = doc.export('text.dxf')
polyline_exporter = doc.export('polyline.dxf')
try:
for entity in doc.modelspace():
if entity.dxftype() == 'LINE':
line_exporter.write(entity)
elif entity.dxftype() == 'TEXT':
text_exporter.write(entity)
elif entity.dxftype() == 'POLYLINE':
polyline_exporter.write(entity)
finally:
line_exporter.close()
text_exporter.close()
polyline_exporter.close()
doc.close()
Supported DXF types:
3DFACE, ARC, ATTDEF, ATTRIB, CIRCLE, DIMENSION, ELLIPSE, HATCH, HELIX, IMAGE, INSERT,
LEADER, LINE, LWPOLYLINE, MESH, MLEADER, MLINE, MTEXT, POINT, POLYLINE, RAY, SHAPE,
SOLID, SPLINE, TEXT, TRACE, VERTEX, WIPEOUT, XLINE
Transfer simple entities to another DXF document, this works for some supported entities, except for entities with
strong dependencies to the original document like INSERT look at :meth:`~ezdxf.layouts.BaseLayout.add_foreign_entity`
for all supported types:
.. code-block:: Python
newdoc = ezdxf.new()
msp = newdoc.modelspace()
# line is an entity from a big source file
msp.add_foreign_entity(line)
# and so on ...
msp.add_foreign_entity(lwpolyline)
msp.add_foreign_entity(mesh)
msp.add_foreign_entity(polyface)
Transfer MESH and POLYFACE (dxftype for POLYFACE and POLYMESH is POLYLINE!) entities into a new DXF document by
the :class:`MeshTransformer` class:
.. code-block:: Python
from ezdxf.render import MeshTransformer
# mesh is MESH from a big source file
t = MeshTransformer.from_mesh(mesh)
# create a new MESH entity from MeshTransformer
t.render(msp)
# polyface is POLYFACE from a big source file
t = MeshTransformer.from_polyface(polyface)
# create a new POLYMESH entity from MeshTransformer
t.render_polyface(msp)
Another way to import entities from a big source file into new DXF documents is to split the big file into
smaller parts and use the :class:`~ezdxf.addons.importer.Importer` add-on for a more safe entity import.
.. autofunction:: opendxf
.. autofunction:: modelspace
.. autofunction:: single_pass_modelspace
.. class:: IterDXF
.. automethod:: export
.. automethod:: modelspace
.. automethod:: close
.. class:: IterDXFWriter
.. automethod:: write
.. automethod:: close
|