Mirror object in 2D plane with pyautocad

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))
Figure 1: Line

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))
Figure 2.1: Mirror image of line l1

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))
Figure 2.2: Mirror image of line l1 (Reference line shifted by 50 units)

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.

Leave a Reply

5 thoughts on “Mirror object in 2D plane with pyautocad

  1. where can I find complete documentation of pyatuocad?
    I am eager to learn but cannot find.

    1. Hi Sulav,

      Theres no such complete complete documentation for Pyautocad, hence we are trying to build one. But for general information you can always refer to ActiveX documentation as well as Pyautocad’s manual page.

      Thank you!

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Close

Meta