Using recursed entities to count symbols

Using recursed entities to count symbols
 1# Counting certain entities within a layer, first without recursiing into sub-blocks, then with recursion
 2
 3ents = impact.active_drawing.active_layer.root_block.entities
 4count = 0
 5for ent in ents:
 6    if ent.entity_type == ipEntityType.etInsert:
 7        ent_insert = IInsertEntity(ent._com_obj)
 8        if ent_insert.insert_type == ipInsertType.itSymbol:
 9            ent_casted = ISymbolInsert(ent_insert._com_obj)
10            count = count +1
11
12impact.gui.output_toolbox.add(str(count) + " symbols found at top level")
13
14
15
16rec_ents = impact.active_drawing.active_layer.root_block.recursed_entities
17
18# rec_ents will be an IRecursedEntities collection
19count = 0
20for rec_ent in rec_ents:
21
22    # rec_ent will be an IRecursedEntity object, which holds an entity and a transformation
23    ent = rec_ent.entity
24    if ent.entity_type == ipEntityType.etInsert:
25        ent_insert = IInsertEntity(ent._com_obj)
26        if ent_insert.insert_type == ipInsertType.itSymbol:
27            ent_casted = ISymbolInsert(ent_insert._com_obj)
28            count = count +1
29
30impact.gui.output_toolbox.add(str(count) + " symbols found in entire layer")
31