Splitting a bezier at its midpoint¶
Splitting a bezier at its midpoint¶
1# This example selects all visible entities in the active block and deletes them. A
2# bezier is created and its midpoint found. The bezier 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 the selected 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 # Use the impact.creator to create some vectors
24 v1 = c.vector(0,0)
25 v2 = c.vector(10,20)
26 v3 = c.vector(30,20)
27 v4 = c.vector(40,0)
28
29 # Move to the origin of the active block
30 ab.move_ad(0, 0)
31
32 # Create a bezier
33 bezier1 = ab.bezier_a(v1, v2, v3, v4)
34
35 # Get the midpoint of the bezier
36 mid_point = bezier1.get_along(0.5)
37
38 # Split the bezier at its midpoint
39 bezier2 = bezier1.split_at_point(mid_point)
40
41 # View the extents of the active window
42 impact.gui.active_window.view_extents()
43
44else:
45
46 # Display a message in the output toolbox
47 impact.gui.output_toolbox.add("unable to continue: no active drawing")
48