Polar AutoCAD arrays using pyautocad

In our previous blog post from this series of pyautocad articles I discussed rectangular arrays. Now, in this post, I will introduce and document polar arrays in AutoCAD and how to create and modify them with pyautocad in Python.

Setting up the drawing in Python

As usual, we will set up our work environment by importing the pyautocad library to make AutoCAD interact with python.

from pyautocad import Autocad, APoint, aDouble
from math import *

acad = Autocad(create_if_not_exists=True)

Creating some AutoCAD object as base for the polar array

To create an array, we will use the circle as an object. We will draw the circle using the AddCircle method. Also, we will store this circle in a variable “c1” to apply the array command against the created circle.

c1 = acad.model.AddCircle(APoint(100, 100), 100)
Figure 1: Circle

Concept of a polar array in AutoCAD

AutoCAD determines the distance from the array’s center point to a reference point on the last object selected. The reference point used depends on the type of object previously selected. AutoCAD uses the center point of a circle or arc, the insertion point of a block or shape, the start point of the text, and one endpoint of a line or trace.

Creating a polar array in AutoCAD with pyautocad in Python

Before creating the polar array, let’s check the syntax for creating the polar array.

# Syntax:

object.ArrayPolar(NumberOfObjects, AngleToFill, CenterPointofArray)

# Angle shall be specified in radians
# Center point of array shall be specified in the form of three-element array of doubles

Using the above-mentioned syntax, we will create the array.


arr1 = c1.ArrayPolar(10, round(pi*180/180), aDouble(550, 600, 0))
Figure 2: Polar array of circle

If you are interested in AutoCAD scripting and AutoCAD automatization you can find additional pyautocad and pywin32 documentation under the AutoCAD section of this blog. For example I also documented how to work with 3D mesh objects in AutoCAD using pyautocad, and how to modify solid objects in AutoCAD with pyautocad. I also documented how to integrate pywin32 with AutoCAD and how to e.g. create a aDouble constructor with pywin32.

You May Also Like

Leave a Reply

2 comments

Shaunak Deshpande says:

I tried using the above code to create a polar array, but it’s showing me an error, and I cannot understand the problem exactly.
arr1 = c1.ArrayPolar(10, round(pi*180/180), aDouble(0, 0, 0))
Also, can you tell me any other resources or tutorials where I can learn pyautocad in detail?

Hello Mr. Deshpande,

Thanks for your question. Can you please share the error that is getting displayed? So that we can get to the solution.

Talking about tutorials, as of now there is no such well-structured tutorial that we have come across, that’s why we are trying to document every possible utility that has been offered by the pyautocad module, as well as finding solutions to overcome some of the drawbacks of this module on this page. Hope we will be creating a full-fledged tutorial on the integration of python and Autocad very soon.

You can check our other blogs too: https://www.supplychaindataanalytics.com/category/pyautocad-en/

Have a nice day!

Leave a Reply

Your email address will not be published. Required fields are marked *

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