SymbolInsert example¶
SymbolInsert example¶
1# this example inserts a symbol in various modes using relative
2# coordinates and vector 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 symbol_name = "Die Face"
27 scale_value = 2
28 angle = 45
29 mirror_x = 0
30 mirror_y = 0
31
32 # insert the symbol as a symbol
33 offset = impact.creator.vector(100,0)
34 symbol_insert = ab.symbol_insert(symbol_name, offset, scale_value, angle, mirror_x, mirror_y, ipSymbolInsertMode.simAsSymbols)
35
36 # check the symbol was inserted
37 if symbol_insert is not None:
38 ot.add("successfully inserted symbol '" + str(symbol_name) + "' as a symbol")
39 else:
40 ot.add("failed to insert symbol '" + str(symbol_name) + "' as a symbol")
41
42 # insert the symbol as a block
43 position = impact.creator.vector(100,0)
44 block_insert = ab.symbol_insert(symbol_name, position, scale_value, angle, mirror_x, mirror_y, ipSymbolInsertMode.simAsBlocks)
45
46 # check the symbol was inserted
47 if block_insert is not None:
48 ot.add("successfully inserted symbol '" + str(symbol_name) + "' as a block")
49 else:
50 ot.add("failed to insert symbol '" + str(symbol_name) + "' as a block")
51
52 # insert the symbol as a block with symbols
53 position = impact.creator.vector(100,0)
54 block_insert = ab.symbol_insert(symbol_name, position, scale_value, angle, mirror_x, mirror_y, ipSymbolInsertMode.simAsBlocksWithSymbols)
55
56 # check the symbol was inserted
57 if block_insert is not None:
58 ot.add("successfully inserted symbol '" + str(symbol_name) + "' as a block with symbols")
59 else:
60 ot.add("failed to insert symbol '" + str(symbol_name) + "' as a block with symbols")
61
62 # insert the symbol as a entities, note when inserting as entities the
63 # IActiveBlock.symbol_insert_a() method returns None
64 position = impact.creator.vector(100,0)
65 ab.symbol_insert(symbol_name, position, scale_value, angle, mirror_x, mirror_y, ipSymbolInsertMode.simAsGeometry)
66
67 # View the extents of the active window
68 impact.gui.active_window.view_extents()