LineTanTan example (Python)

LineTanTan example (Python)
 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 = 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    # move to the origin of the active block
39    ab.move_ad(100, 100)
40
41    # create a clockwise short arc
42    arc2 = None
43    try:
44        arc2 = ab.arc( offset, radius, 0, 1 )
45    except Exception as exc:
46        pass
47    impact.gui.output_toolbox.add(f"Failed to create object via ab.arc(): {exc}")
48
49    # create a local variable for the From option
50    toPoint = None
51    try:
52        toPoint = impact.creator.vector(100,100)
53    except Exception as exc:
54        pass
55    impact.gui.output_toolbox.add(f"Failed to create object via impact.creator.vector(): {exc}")
56
57    # create a local variables for the Near options
58    near1 = arc1.get_along( 0.5 )  # the midpoint of the first arc
59    near2 = arc2.get_along( 0.5 )  # the midpoint of the second arc
60
61    # create the line
62    line1 = ab.line_tan_tan( arc1, arc2, near1, near2 )
63
64    # check the line was created
65    if not line1.isNone():
66
67        # display the length of the line in the output toolbox
68        impact.gui.output_toolbox.add("Line length: " + line1.length)