Splitting a line at its midpoint¶
Splitting a line at its midpoint¶
1# This example selects all visible entities in the active block and deletes them.
2# A line is created and its midpoint found. The line is then split at its
3# midpoint. Finally the extents of the active window are shown.
4
5# Create a local variable for the active drawing
6ad = impact.active_drawing
7
8# Check that there is an active drawing
9if not ad.isNone():
10
11 # Create a local variable for the active block
12 ab = ad.active_layer.active_block
13
14 # Select all visible entities in the active block
15 ab.select_all()
16
17 # Delete all the entities in the active block
18 ab.delete_selected()
19
20 # Create a local variable for the impact.creator object
21 c = impact.creator
22
23 # Create some vectors
24 v1 = c.vector(0,0)
25 v2 = c.vector(10,20)
26
27 # Move to the point defined by the vector v1
28 ab.move_a(v1)
29
30 # Draw a line to the point defined by the vector v2
31 line1 = ab.line_a(v2)
32
33 # Get the midpoint of the line
34 mid_point = line1.get_along(0.5)
35
36 # Split the line at its midpoint
37 line2 = line1.split_at_point(mid_point)
38
39 # View the extents of the active window
40 impact.gui.active_window.view_extents()
41
42else:
43
44 # Display a message in the output toolbox
45 impact.gui.output_toolbox.add("unable to continue: no active drawing")