ezdxf.select
The ezdxf.select
module provides entity selection capabilities, allowing users to select entities based on various shapes such as windows, points, circles, polygons, and fences.
The selection functions bbox_inside
and bbox_outside
work similarly to the inside and outside selection tools in CAD applications but the selection is based on the bounding box of the DXF entities rather than their actual geometry.
The bbox_overlap
function works similarly to crossing selection in CAD applications. Entities that are outside the selection shape but whose bounding box overlapps the selection shape are included in the selection. This is not the case with crossing selection in CAD applications.
The selection functions accept any iterable of DXF entities as input and return an ezdxf.query.EntityQuery
container, that provides further selection tools based on entity type and DXF attributes.
Select all entities from the modelspace inside a window defined by two opposite vertices:
import ezdxf
from ezdxf import select
doc = ezdxf.readfile("your.dxf")
msp = doc.modelspace()
# Define a window for selection
window = select.Window((0, 0), (10, 10))
# Select entities inside the window from modelspace
selected_entities = select.bbox_inside(window, msp)
# Iterate over selected entities
for entity in selected_entities:
print(entity)
tut_entity_selection
The following selection functions are implemented:
bbox_inside
bbox_outside
bbox_overlap
bbox_chained
bbox_crosses_fence
point_in_bbox
bbox_inside
bbox_outside
bbox_overlap
bbox_chained
bbox_crosses_fence
point_in_bbox
The following selection shapes are implemented:
Window
Circle
Polygon
Window
Circle
Polygon