I'm trying to select the densest (in terms contained elements) areas of a DXF layer in ezdxf.
These boxes are evenly spaced and shaped.
In other words: given a BoundingBox2d instance bbox, how to obtain number of entities (lines, poly lines, basically - everything) contained in ezdxf.layouts.layout.Modelspace instance msp within that bbox?
The msp variable contains modelspace with only one variable turned on.
Intuitively, it should be something like:
def count_elements_in_layer_and_bbox(msp: Modelspace, layer: str, bbox: BoundingBox2d) -> int
# turn off all layers but one
for l in msp.layers:
if layer == l.dxf.name:
l.on()
else:
l.off()
# get entities within the bbox - this is the line I don't know how to approach
entities = msp.intersect(bbox).dxf.entities
return len(enitites)
ezdxfis a DXF file format interface not a CAD application. So switching layers on/off has no influence on the content of the modelspace.But
ezdxfgives you other tools to select entities based on DXF attributes like thequery()method. BTW a layer is just a DXF attribute and not a real container:Read the docs for query() and also read the limitations of the bbox module.