TrimCorner example

TrimCorner example
 1# this example creates two lines that intersect each other
 2# at right angles, the lines are then trimmed so that they do
 3# not intersect but meet at each end
 4
 5# Create a local variable for the impact.gui
 6g = impact.gui
 7
 8# Create a local variable for the output toolbox
 9ot = g.output_toolbox
10
11# Clear the output toolbox
12ot.clear()
13
14# Create a local variable for the active drawing
15ad = impact.active_drawing
16
17# check there is an active drawing
18if ad.isNone():
19
20    # display a message in the output toolbox
21    ot.add("Unable to continue: there is no active drawing")
22
23else:
24
25    # create a local variable for the active block
26    ab = ad.active_layer.active_block
27
28    # move to the origin of the active block
29    ab.move_ad(0, 0)
30
31    # create a horizontal line
32    line1 = ab.line_ad(110, 0)
33
34    # move to a position below the horizontal line and to the left of its end
35    ab.move_ad(100, -10)
36
37    # create a vertical line that intersects the first horizontal line
38    line2 = ab.line_ad(100, 100)
39
40    # check the lines were created
41    if not line1 is None and not line2 is None:
42
43        # perform the trim operation
44        ab.trim_corner(line1, line2, line1.start, line2.end)
45
46    else:
47
48        # add an error message to the output toolbox
49        ot.add("one or more lines could not be created")
50
51        # view the extents
52        g.active_window.view_extents()