LinePointTangent example (Python)¶
LinePointTangent example (Python)¶
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 = None
24 try:
25 offset = impact.creator.vector(radius,radius)
26 except Exception as exc:
27 pass
28 impact.gui.output_toolbox.add(f"Failed to create object via impact.creator.vector(): {exc}")
29
30 # create a clockwise short arc
31 arc1 = None
32 try:
33 arc1 = ab.arc( offset, radius, 0, 1 )
34 except Exception as exc:
35 pass
36 impact.gui.output_toolbox.add(f"Failed to create object via ab.arc(): {exc}")
37
38 # create a local variable for the From option
39 from_point = None
40 try:
41 from_point = impact.creator.vector(100,100)
42 except Exception as exc:
43 pass
44 impact.gui.output_toolbox.add(f"Failed to create object via impact.creator.vector(): {exc}")
45
46 # create a local variable for the Near option
47 near = arc1.get_along( 0.5 ) # the midpoint of the arc
48
49 # create the line
50 line1 = ab.line_point_tangent( from_point, arc1, near )
51
52 # check the line was created
53 if not line1.isNone():
54
55 # display the length of the line in the output toolbox
56 impact.gui.output_toolbox.add("Line length: " + line1.length)