MirrorAboutAxis (Python)¶
MirrorAboutAxis (Python)¶
1# This example shows the use of the matrix MirrorAboutAxis function
2
3# Check that there is an active drawing
4ad = impact.active_drawing
5if ad.isNone():
6 impact.gui.output_toolbox.add('Unable to continue: there is no active drawing')
7else:
8 # Create a matrix for the transformation
9 m = None
10 try:
11 m = impact.creator.matrix()
12 except Exception as exc:
13 pass
14 impact.gui.output_toolbox.add(f"Failed to create object via impact.creator.matrix(): {exc}")
15
16 # Create some vectors
17 v1 = None
18 try:
19 v1 = impact.creator.vector(0,0)
20 except Exception as exc:
21 pass
22 impact.gui.output_toolbox.add(f"Failed to create object via impact.creator.vector(): {exc}")
23 v2 = None
24 try:
25 v2 = impact.creator.vector(20,40)
26 except Exception as exc:
27 pass
28 impact.gui.output_toolbox.add(f"Failed to create object via impact.creator.vector(): {exc}")
29 v3 = None
30 try:
31 v3 = impact.creator.vector(20,20)
32 except Exception as exc:
33 pass
34 impact.gui.output_toolbox.add(f"Failed to create object via impact.creator.vector(): {exc}")
35 v4 = None
36 try:
37 v4 = impact.creator.vector(30,20)
38 except Exception as exc:
39 pass
40 impact.gui.output_toolbox.add(f"Failed to create object via impact.creator.vector(): {exc}")
41
42 # Draw the diagonal line, showing the mirror axis
43 impact.active_block.move_a( v1 )
44 line1 = impact.active_block.line_a( v2 )
45
46 # Draw the horizontal line
47 impact.active_block.move_a( v3 )
48 line2 = impact.active_block.line_a( v4 )
49
50 # Create the mirror transformation matrix using the two points used for the diagonal line
51 m.mirror_about_axis( v1, v2 )
52
53 # Perform the transformation on line2
54 line2.transform( m )
55
56 ad.active_window.view_extents()