LineTanTan example¶
LineTanTan example¶
1# this example creates two arcs in the active block and then creates a line
2# between a tangent on each of the arcs, the length of the line is then
3# displayed in the output toolbox
4
5# check there is an active drawing
6if impact.active_drawing.isNone():
7
8 # display a message in the output toolbox
9 impact.gui.output_toolbox.add("Unable to continue: there is no active drawing")
10
11else:
12
13 # create a local variable for the active block
14 ab = impact.active_drawing.active_layer.active_block
15
16 # move to the origin of the active block
17 ab.move_ad(0, 0)
18
19 # create a local variable for the radius
20 radius = 50
21
22 # create a vector for the offset
23 offset = impact.creator.vector(radius,radius)
24
25 # create a clockwise short arc
26 arc1 = ab.arc(offset, radius, 0, 1)
27
28 # move to the origin of the active block
29 ab.move_ad(100, 100)
30
31 # create a clockwise short arc
32 arc2 = ab.arc(offset, radius, 0, 1)
33
34 # create a local variable for the From option
35 to_point = impact.creator.vector(100,100)
36
37 # create a local variables for the Near options
38 near1 = arc1.get_along(0.5) # the midpoint of the first arc
39 near2 = arc2.get_along(0.5) # the midpoint of the second arc
40
41 # create the line
42 line1 = ab.line_tan_tan(arc1, arc2, near1, near2)
43
44 # check the line was created
45 if line1 is not None:
46
47 # display the length of the line in the output toolbox
48 impact.gui.output_toolbox.add("Line length: " + str(line1.length))