Example Of Extend¶
Example Of Extend¶
1# this example creates a line in the active block and displays its
2# length in the output toolbox, the line is then extended and the
3# new length of the line is displayed in the output toolbox
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 # move to the origin of the active block
26 ab.move_ad(0, 0)
27
28 # create a local variable for the position
29 position_x = 100
30 position_y = 100
31
32 # create a line
33 line1 = ab.line_ad(position_x, position_y)
34
35 # display the length of the line in the output toolbox
36 ot.add(line1.length)
37
38 # check the line was created
39 if line1 is not None:
40
41 # extend the line from the end
42 line1.extend(100, False)
43
44 # display the length of the line in the output toolbox
45 ot.add(line1.length)