LinePointTangent example¶
LinePointTangent example¶
1# this example creates an arc in the active block and then creates a line
2# to a tangent on the created arc, the length of the line is then displayed in
3# 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 # create a local variable for the From option
29 from_point = impact.creator.vector(100,100)
30
31 # create a local variable for the Near option
32 near = arc1.get_along(0.5) # the midpoint of the arc
33
34 # create the line
35 line1 = ab.line_point_tangent(from_point, arc1, near)
36
37 # check the line was created
38 if line1 is not None:
39
40 # display the length of the line in the output toolbox
41 impact.gui.output_toolbox.add("Line length: " + str(line1.length))