-
Hi, I'm using ezdxf to convert DXF file to image from anyone around me, and there are files way too complex to convert it in a reasonable time (let's say less than 2 minutes). Is there any way to compute something like a complexity indice, or analyse file to know that some part will be very long to draw ? Thanks in advance for your answers :) PS: Thanks for this easy to use tool ❤️ open source community ❤️ |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The only heuristic i can think of is to count the DXF entities recursively for a layout like the import ezdxf
from ezdxf.layouts import BaseLayout
def count_entities(layout: BaseLayout) -> int:
"""Counts the DXF entities in the given layout recursively.
This is not an exact count, not include are:
- DIMENSION geometry block
- ACAD_TABLE geometry block
- XREF content
- multiplied INSERT entities
- ...
"""
count = len(layout)
doc = layout.doc
if doc is None:
return count
for insert in layout.query("INSERT"):
block = insert.block()
if block:
count += count_entities(block)
return count
def main():
doc = ezdxf.readfile("big.dxf")
print(count_entities(doc.modelspace()))
if __name__ == "__main__":
main() Often is loading such a big file already a problem, so a size check is maybe also a good idea. Don't ask for a reasonable size limit, this depends on your system - modern workstation with 128 GB RAM and fast NVMe vs old potato notebook with 8GB RAM and a HDD. |
Beta Was this translation helpful? Give feedback.
The only heuristic i can think of is to count the DXF entities recursively for a layout like the
modelspace
.