Skip to content

Compute file complexity #987

Answered by mozman
mgohin asked this question in Q&A
Dec 8, 2023 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

The only heuristic i can think of is to count the DXF entities recursively for a layout like the modelspace.

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)…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@mgohin
Comment options

Answer selected by mgohin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants