SymbolInsertA2 example (Python)

SymbolInsertA2 example (Python)
 1# this example inserts a symbol in various modes using absolute
 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    symbolName = "Die Face"
27    scaleValue = 2
28    angle = 45
29    mirrorX = 0
30    mirrorY = 0
31
32    # insert the symbol as a symbol
33    position = None
34    try:
35        position = impact.creator.vector(100,100)
36    except Exception as exc:
37        pass
38    impact.gui.output_toolbox.add(f"Failed to create object via impact.creator.vector(): {exc}")
39    symbolInsert = ab.symbol_insert_a2( symbolName, position, scaleValue, angle, mirrorX, mirrorY, ipSymbolInsertMode.simAsSymbols )
40
41    # check the symbol was inserted
42    if not symbolInsert.isNone():
43        ot.add("successfully inserted symbol '" + symbolName + "' as a symbol")
44    else:
45        ot.add("failed to insert symbol '" + symbolName + "' as a symbol")
46
47    # insert the symbol as a block
48    position = None
49    try:
50        position = impact.creator.vector(200,100)
51    except Exception as exc:
52        pass
53    impact.gui.output_toolbox.add(f"Failed to create object via impact.creator.vector(): {exc}")
54    blockInsert = ab.symbol_insert_a2( symbolName, position, scaleValue, angle, mirrorX, mirrorY, ipSymbolInsertMode.simAsBlocks )
55
56    # check the symbol was inserted
57    if not blockInsert.isNone():
58        ot.add("successfully inserted symbol '" + symbolName + "' as a block")
59    else:
60        ot.add("failed to insert symbol '" + symbolName + "' as a block")
61
62    # insert the symbol as a block with symbols
63    position = None
64    try:
65        position = impact.creator.vector(300,100)
66    except Exception as exc:
67        pass
68    impact.gui.output_toolbox.add(f"Failed to create object via impact.creator.vector(): {exc}")
69    blockInsert = ab.symbol_insert_a2( symbolName, position, scaleValue, angle, mirrorX, mirrorY, ipSymbolInsertMode.simAsBlocksWithSymbols )
70
71    # check the symbol was inserted
72    if not blockInsert.isNone():
73        ot.add("successfully inserted symbol '" + symbolName + "' as a block with symbols")
74    else:
75        ot.add("failed to insert symbol '" + symbolName + "' as a block with symbols")
76
77    # insert the symbol as a entities, note when inserting as entities the
78    # IActiveBlock.symbol_insert_a method returns None
79    position = None
80    try:
81        position = impact.creator.vector(400,100)
82    except Exception as exc:
83        pass
84    impact.gui.output_toolbox.add(f"Failed to create object via impact.creator.vector(): {exc}")
85    ab.symbol_insert_a2(symbolName, position, scaleValue, angle, mirrorX, mirrorY, ipSymbolInsertMode.simAsGeometry)
86
87    # View the extents of the active window
88    impact.gui.active_window.view_extents()