We have seen how to draw some of the basic objects, fetching their basic properties and some other features too in our previous blog posts from this pyautocad series. In this particular blog post, we will look at, how we can create a mirror image of any object.
Setting up the environment for mirror objects in Python
As usual, we will start by importing our pyautocad library and will draw a line to create a mirror image of the same.
from pyautocad import Autocad, APoint acad = Autocad(create_if_not_exists=True) l1 = acad.model.AddLine(APoint(0, 0, 0), APoint(100, 100, 0))
Creating mirror images with pyautocad
Creating a mirror image from an existing object needs a very simple command. Please check the syntax given below.
# Syntax: object.Mirror(point1, point2)
Here, point1 and point2 are the start point and endpoint of the line with reference to which the object is being mirrored.
For instance, we will create a mirror image of the existing line with reference to an invisible line starting from point (100, 100, 0) to point (0, 100, 0).
l1.Mirror(APoint(100, 100, 0), APoint(100, 0, 0))
Now, let us move this imaginary line of reference 50 units away from the point (150, 0, 0) and check.
l1.Mirror(APoint(150, 100, 0), APoint(150, 0, 0))
As we can see from Figure 2.2, I have purposely drawn the reference line in the middle.
With reference to this central line, the mirror image of line l1 is created on the right-hand side of the reference line.
Concluding remarks regarding mirror functions with pyautocad
The reference line we specify in the mirror command can start from any point and end at any point.
E.g. rather than specifying start point, endpoint as (100, 100, 0), (100, 0, 0) we can also write (100, 1582, 0), (100, -652.28, 0).
i.e. In both cases, the result will be the same as shown in Figure 2.1. Because just the length of the reference line is changing and not the position.
Civil engineer interested in automation in core subjects such as civil, mechanical and electrical, using IT skills comprising cloud computing, devops, programming languages and databases along with the technical skills gained while working as a civil engineer since past 3 years.