Insertions example

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