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
13_INSERT_TYPE_AS_STRING_MAP = {
14 ipInsertType.itBlock: "block",
15 ipInsertType.itSymbol: "symbol",
16 ipInsertType.itLayer: "layer",
17 ipInsertType.itMasterLayer: "master layer",
18 ipInsertType.itOther: "other",
19}
20
21def insert_type_as_string(it):
22 return _INSERT_TYPE_AS_STRING_MAP.get(it, "?")
23
24
25# Clear the output toolbox
26ot.clear()
27
28# Check there is an active drawing
29if ad.isNone():
30
31 # Add a message to the output toolbox
32 ot.add("unable to continue: no active drawing")
33
34else:
35
36 # Get the inserts in the active layer
37 inserts = ad.active_layer.root_block.insertions
38
39 # Iterate the inserts
40 for insert in inserts:
41
42 # Add the type of the insert as a string to the output toolbox
43 ot.add(insert_type_as_string(insert.insert_type))