Example Of SetActiveBlock

Example Of SetActiveBlock
 1# this example creates 4 lines, creates a block from lines and creates another
 2# block insert of the new block
 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    # ensure no existing entities are selected
25    ab.select_none()
26
27    # automatically select new entities
28    ab.auto_select = 1
29
30    # move to the origin of the active block
31    ab.move_ad(0, 0)
32
33    # draw some geometry
34    ab.lined(100, 0)
35    ab.lined(0, 100)
36    ab.lined(-100, 0)
37    ab.lined(0, -100)
38
39    # stop automatically selecting new entities
40    ab.auto_select = 0
41
42    # create a new block from the selected entities in the active block
43    block_insert = ab.block("Block 1", "description", ipBlockPosition.bpLeft)
44
45    # check the block was created succesfully
46    if block_insert is not None:
47
48        # now activate the block insert
49        block_insert.activate()
50
51        # goto the parent block (which is the layer)
52        ad.active_layer.set_active_block(ipActiveBlock.abParent)