BlockInsertA example

BlockInsertA example
 1# this example creates 4 lines, creates a block from the lines
 2# and creates another block insert of the new block using absolute
 3# coordinates and vector parameters
 4
 5# Create a local variable for the output toolbox
 6ot = impact.gui.output_toolbox
 7
 8# Clear the output toolbox
 9ot.clear()
10
11# Create a local variable for the active drawing
12ad = impact.active_drawing
13
14# check there is an active drawing
15if ad.isNone():
16
17    # display a message in the output toolbox
18    ot.add("Unable to continue: there is no active drawing")
19
20else:
21
22    # create a local variable for the active block
23    ab = ad.active_layer.active_block
24
25    # ensure no existing entities are selected
26    ab.select_none()
27
28    # automatically select new entities
29    ab.auto_select = 1
30
31    # move to the origin of the active block
32    ab.move_ad(0, 0)
33
34    # draw some geometry
35    ab.lined(100, 0)
36    ab.lined(0, 100)
37    ab.lined(-100, 0)
38    ab.lined(0, -100)
39
40    # stop automatically selecting new entities
41    ab.auto_select = 0
42
43    # create a new block from the selected entities in the active block
44    block_insert = ab.block("Block 1", "description", ipBlockPosition.bpLeft)
45
46    # check the block was created succesfully
47    if not block_insert.isNone():
48        ot.add("Successfully created a new block")
49
50        # get the block that the block insert was an insert of and create
51        # another insert of that block
52        block = block_insert.inserted_object
53
54        # create some local variables for the position, angle, scale etc. for the
55        # block insert
56        position = impact.creator.vector(500,500)
57        scale = 2
58        angle = 0
59        mirror_x = 0
60        mirror_y = 0
61
62        # create the block insert
63        new_block_insert = ab.block_insert_a(block, position, scale, angle, mirror_x, mirror_y)
64
65        # display an appropriate message in the output toolbox
66        if not new_block_insert.isNone():
67            ot.add("Successfully created a new block insert")
68        else:
69            ot.add("An error occured creating the new block insert")
70
71    else:
72
73        # display an error message in the output toolbox
74        ot.add("An error occured creating the block")
75
76        # View the extents of the active window
77        impact.gui.active_window.view_extents()
78