Selecting a line¶
Selecting a line¶
1# this example creates a rectangle in the active block and selects the top and
2# bottom lines of the rectangle
3
4# check there is an active drawing
5if impact.active_drawing.isNone():
6
7 # display a message in the output toolbox
8 impact.gui.output_toolbox.add("Unable to continue: there is no active drawing")
9
10else:
11
12 # create a local variable for the active block
13 ab = impact.active_drawing.active_layer.active_block
14
15 # move to the origin in the active block
16 ab.move_ad(0, 0)
17
18 # create a local variable for the rectangle size
19 rectangle_size = 100
20
21 # create a line
22 line1 = ab.lined(rectangle_size, 0)
23 line2 = ab.lined(0, rectangle_size)
24 line3 = ab.lined(-rectangle_size, 0)
25 line4 = ab.lined(0, -rectangle_size)
26
27 # check the lines were created
28 if not line1.isNone() and not line2.isNone() and not line3.isNone() and not line4.isNone():
29
30 # ensure that all the lines are deselected (auto select may be on)
31 line1.selected = 0
32 line2.selected = 0
33 line3.selected = 0
34 line4.selected = 0
35
36 # Create two vectors that will represent a line that intersects the top
37 # and bottom lines of the rectangle created
38
39 start_point = line1.get_along(0.5) # the mid point of the bottom line
40 end_point = line3.get_along(0.5) # the mid point of the top line
41
42 # Select the top and bottom lines of the rectangle
43 ab.select_by_lined(start_point.x, start_point.y, end_point.x, end_point.y)
44