File: iterdxf_add_to_new_drawing.py

package info (click to toggle)
ezdxf 1.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 104,528 kB
  • sloc: python: 182,341; makefile: 116; lisp: 20; ansic: 4
file content (49 lines) | stat: -rw-r--r-- 1,444 bytes parent folder | download
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
# Copyright (c) 2020, Manfred Moitzi
# License: MIT License
import time
import pathlib
from collections import Counter
import ezdxf
from ezdxf.addons import iterdxf

CWD = pathlib.Path("~/Desktop/Outbox").expanduser()
if not CWD.exists():
    CWD = pathlib.Path(".")

# ------------------------------------------------------------------------------
# This example shows how iterate over very big DXF files without loading them
# into memory. This takes much longer, but it's maybe the only way to process
# these very large files.
#
# This example uses the modelspace iterator to copy all supported entities from
# modelspace without any resources defined in the source DXF document.
#
# docs: https://ezdxf.mozman.at/docs/addons/iterdxf.html#ezdxf.addons.iterdxf.modelspace
# ------------------------------------------------------------------------------

BIGFILE = ezdxf.options.test_files_path / "GKB-R2010.dxf"


def main():
    doc = ezdxf.new()
    msp = doc.modelspace()

    print("Modelspace Iterator:")
    counter = Counter()
    t0 = time.perf_counter()
    for entity in iterdxf.modelspace(BIGFILE):
        counter[entity.dxftype()] += 1
        try:
            msp.add_foreign_entity(entity)
        except ezdxf.DXFTypeError:
            pass

    ta = time.perf_counter() - t0
    print(f"Processing time: {ta:.2f}s")

    print("Saving as ezdxf.dxf")
    doc.saveas(CWD / "ezdxf.dxf")


if __name__ == '__main__':
    main()