Insertions example (Python)

Insertions example (Python)
 1# This example displays the type of each insert in the active layer
 2
 3# Define a function to convert an ipInsertType enumeration
 4# constant to a string
 5def InsertTypeAsString( it ):
 6    if it == ipInsertType.itBlock:
 7        Str = "block"
 8    elif it == ipInsertType.itSymbol:
 9        Str = "symbol"
10    elif it == ipInsertType.itLayer:
11        Str = "layer"
12    elif it == ipInsertType.itMasterLayer:
13        Str = "master layer"
14    elif it == ipInsertType.itOther:
15        Str = "other"
16    else:
17        Str = "?"
18    InsertTypeAsString = Str
19    return locals().get("InsertTypeAsString")
20
21# Create a local variable for the output toolbox
22ot = impact.gui.output_toolbox
23
24# Clear the output toolbox
25ot.clear()
26
27# Create a local variable for the active drawing
28ad = impact.active_drawing
29
30# Check there is an active drawing
31if ad.isNone():
32
33    # Add a message to the output toolbox
34    ot.add("unable to continue: no active drawing")
35
36else:
37
38    # Get the inserts in the active layer
39    inserts = ad.active_layer.root_block.insertions
40
41    # Iterate the inserts
42    for insert in inserts :
43
44        # Add the type of the insert as a string to the output toolbox
45        ot.add(InsertTypeAsString( insert.insert_type ))