Getting all entities within a specified bounding box #600
-
Say i was given four(rectangle) or five(polygon) coordinates of a dxf can I get all entities that lie within those cordinates? I have this code where I can get the starting and ending points of each entity in the dxf
I was checking for a way if I could get all entities that lie within a specified bounding box. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 4 replies
-
Inside CheckGiven two bounding boxes # for 3D BoundingBox(), the default in most cases:
print(box_b.all_inside(box_a.cube_vertices()))
# for 2D BoundingBox2d():
print(box_b.all_inside(box_a.rect_vertices())) Intersection Checkprint(box_b.intersect(box_a)) |
Beta Was this translation helpful? Give feedback.
-
Better, faster solution and works for 2d and 3d bounding box the same way: print(box_b.inside(box_a.extmin) and box_b.inside(box_a.extmax)) |
Beta Was this translation helpful? Give feedback.
-
The The result is a bounding box class: https://ezdxf.mozman.at/docs/math.html#boundingbox from ezdxf.math import BoundingBox
dxf_types = ['ARC','CIRCLE','HATCH','INSERT','LINE','LWPOLYLINE','MTEXT']
search_box = BoundingBox([(495, 585), (547, 585), (547, 537), (495, 537), (495, 585)])
cache = bbox.Cache()
for dxf_type in dxf_types:
entity_boxes = bbox.multi_flat(msp.query(dxf_type), cache=cache)
for entity_box in entity_boxes:
print(search_box.inside(entity_box.extmin) and search_box.inside(entity_box.extmax))
print(cache) # if there are very few hits and you don't reuse the cache for further calculations, you don't need a cache! A cache is nothing magical and no one seems to read this part of the documentation: https://ezdxf.mozman.at/docs/bbox.html#caching-strategies |
Beta Was this translation helpful? Give feedback.
-
Thank You @mozman for the help. Its really a great and helpful library you have built here. |
Beta Was this translation helpful? Give feedback.
The
bbox.extends()
method calculates bounding boxes of entities: https://ezdxf.mozman.at/docs/bbox.htmlThe result is a bounding box class: https://ezdxf.mozman.at/docs/math.html#boundingbox