BlockInsertd example¶
BlockInsertd example¶
1# this example creates 4 lines, creates a block from the lines
2# and creates another block insert of the new block using relative
3# coordinates and double 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 block_insert is not None:
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 angle, scale etc. for the
55 # block insert
56 scale = 2
57 angle = 0
58 mirror_x = 0
59 mirror_y = 0
60
61 # create the block insert
62 new_block_insert = ab.block_insertd(block, 500, 500, scale, angle, mirror_x, mirror_y)
63
64 # display an appropriate message in the output toolbox
65 if new_block_insert is not None:
66 ot.add("Successfully created a new block insert")
67 else:
68 ot.add("An error occured creating the new block insert")
69
70 else:
71
72 # display an error message in the output toolbox
73 ot.add("An error occured creating the block")
74
75 # View the extents of the active window
76 impact.gui.active_window.view_extents()