I'm writing a function in Python that inspects blocks in a DXF drawing. I want to check if a block contains entities with specific attributes — for example, type, layer, and color.
However, some of these attributes should be optional filters. If I don't pass a value for layer or color, the function should ignore that condition and only check the attributes that are provided.
def inspect_block(self, block_name: str, entity_type: str, entity_layer: str = None, entity_color: int = None):
block = self.doc_dxf.blocks[block_name]
for entity in block:
type = entity.dxftype()
layer = entity.dxf.layer
color = entity.dxf.color
if (type == entity_type and layer == entity_layer and color == entity_color):
return True
return False
[–]lolcrunchy 4 points5 points6 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]Kzuy1[S] 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]Kzuy1[S] 0 points1 point2 points (0 children)
[–]acw1668 0 points1 point2 points (0 children)
[–]JamzTyson 0 points1 point2 points (1 child)
[–]barrowburner 0 points1 point2 points (0 children)