SymbolInsertAd2 example (Python)

SymbolInsertAd2 example (Python)
 1# this example inserts a symbol in various modes using absolute
 2# coordinates and double parameters
 3
 4# Create a local variable for the output toolbox
 5ot = impact.gui.output_toolbox
 6
 7# Clear the output toolbox
 8ot.clear()
 9
10# Create a local variable for the active drawing
11ad = impact.active_drawing
12
13# check there is an active drawing
14if ad.isNone():
15
16    # display a message in the output toolbox
17    ot.add("Unable to continue: there is no active drawing")
18
19else:
20
21    # create a local variable for the active block
22    ab = ad.active_layer.active_block
23
24    # create local variables for the symbol name, scale angle and
25    # mirror options
26    symbolName = "Die Face"
27    scaleValue = 2
28    angle = 45
29    mirrorX = 0
30    mirrorY = 0
31
32    # insert the symbol as a symbol
33    symbolInsert = ab.symbol_insert_ad2( symbolName, 100, 100, scaleValue, angle, mirrorX, mirrorY, ipSymbolInsertMode.simAsSymbols )
34
35    # check the symbol was inserted
36    if not symbolInsert.isNone():
37        ot.add("successfully inserted symbol '" + symbolName + "' as a symbol")
38    else:
39        ot.add("failed to insert symbol '" + symbolName + "' as a symbol")
40
41    # insert the symbol as a block
42    blockInsert = ab.symbol_insert_ad2( symbolName, 200, 100, scaleValue, angle, mirrorX, mirrorY, ipSymbolInsertMode.simAsBlocks )
43
44    # check the symbol was inserted
45    if not blockInsert.isNone():
46        ot.add("successfully inserted symbol '" + symbolName + "' as a block")
47    else:
48        ot.add("failed to insert symbol '" + symbolName + "' as a block")
49
50    # insert the symbol as a block with symbols
51    blockInsert = ab.symbol_insert_ad2( symbolName, 300, 100, scaleValue, angle, mirrorX, mirrorY, ipSymbolInsertMode.simAsBlocksWithSymbols )
52
53    # check the symbol was inserted
54    if not blockInsert.isNone():
55        ot.add("successfully inserted symbol '" + symbolName + "' as a block with symbols")
56    else:
57        ot.add("failed to insert symbol '" + symbolName + "' as a block with symbols")
58
59    # insert the symbol as a entities, note when inserting as entities the
60    # IActiveBlock.symbol_insert_a method returns None
61    ab.symbol_insert_ad2(symbolName, 400, 100, scaleValue, angle, mirrorX, mirrorY, ipSymbolInsertMode.simAsGeometry)
62
63    # View the extents of the active window
64    impact.gui.active_window.view_extents()