Top 10 AutoCAD automations in Python

My fellow SCDA member, Tanmay Sawant, and I have developed a considerable amount of documentation covering AutoCAD automatization in Python. It is available on this blog in the form of various blog posts. In this article I want to point out the top 10 AutoCAD tasks that can be automated with Python using e.g. pyautocad, pythoncom and pywin32.

Document management and control

Using pyautocad in Python you can control which drawing should be the currently active one. This allows you to adjust multiple drawings in a single script, i.e. a single workflow. You can switch between drawings, add, remove and edit elements, and access or manipulate relevant AutoCAD objects belonging to the respective drawing. Some examples could be ActiveLayout, ActiveLayer, ActiveViewport, and so on.

Tedious dimensioning, layer setting, text adding etc.

Using pyautocad, pythoncom and pywin32 you can set, edit and select layers in a drawing. You can also adjust the dimensioning in a drawing. Adding and adjusting as well as copying, pasting or deleting text is also easily done with Python modules for AutoCAD.

Importing and exporting from or to other formats

Using Python for AutoCAD enables you to convert between various file formats, for both importing and exporting files. You can handle Excel-files, CAD drawings, dxf- and bmp-files, as well as many other file formats. All of this can take place automatically, i.e. fully automatized in accordance with your Python program.

Adjusting AutoCAD viewport settings

Whenever I add objects of a drawing to paper space I use and adjust viewport settings. I use the viewport settings when producing hard copies for document exchanges with relevant piers. E.g. for hard copy transaction between contractor and client. Even while working with a faster laptop these operations consume a considerable amount of time. Viewport settings can be adjusted in Python, using e.g. pyautocad or pywin32. Transferring this workflow into a Python script will increase your productivity while working with AutoCAD.

Entity and material quantity analysis

Searching for materials or specific entities in a drawing can be done manually in AutoCAD with the search function. But this can be scripted in Python, too. Moreover, transferring this workflow to a Python script will allow you to easily quantify entities and materials by relevant criteria for creating frequency tables and similar.

AutoCAD element tagging

When having multiple occurrences of an AutoCAD entity within a drawing I usually tag entities. Doing this manually takes a long time. I consider this wasted time, since AutoCAD tagging can be automated with Python.

2D and 3D AutoCAD modeling

I can draw 2D and 3D AutoCAD elements directly in Python, i.e. by using a script. I can add these elements to the drawing at a specified location. Moreover, I can manipulate properties and thereby alter the AutoCAD objects in 2D or 3D.

AutoCAD block creation and handling

Defining multiple entities as a block and editing entities within a block can be scripted in Python. Using pyautocad for AutoCAD block handling you can access various relevant properties of both the AutoCAD Block and AutoCAD BlockReferrence objects. For example, you can check whether the block has attributes, adjust its conversion factor between blocks, make it a dynamic or static block, adjust layer assignments etc.

Custom AutoCAD tool developments

Scripting AutoCAD operations in Python enables you to develop custom applications that are specific to your project. Let us say that you e.g. develop warehouse concepts and layouts on a regular basis. You might be working for a warehousing 3PL or similar. You have some layout categories. Each category usually applies the same type of layout. Each layout is unique, however, due to spacing and dimensioning, the amount of storage aisles and work stations etc. Using Python for AutoCAD you can develop a parametrized “drawing”-script for each layout category and then, based on some initial input data, generate the layout that you need for the specific project or client. All you need to do is to select the layout category and to populate relevant input parameter data. This could be done in a userfriendly GUI or in a Excel-file.

Tap into Python functionality beyond AutoCAD

Transferring your formerly manual AutoCAD workflow into Python comes with the benefits of being able to access Python functionality. This comprises functionality that does not come along with AutoCAD itself. You can write functions and methods, access data structures and databases, and use complementary visualization and plotting software. You can content to a front-end with a user friendly interface.

Summary of AutoCAD automatization with Python

In this article I highlighted our motivation for covering AutoCAD automatization in Python. Transferring your manual AutoCAD workflow into a Python script will boost your productivity. Especially if you are facing repetitive or quasi-repetitive AutoCAD tasks on a daily basis. Using Python for AutoCAD you can model 2D and 3D components, group them into blocks and adjust existing blocks, as well as create custom tools for specific operations. You can tag elements, analyze and search your drawing, adjust viewport settings and automate tedious tasks such as dimensioning. You can also manage and control your various documents and convert between file formats (Excel, dwg, CAD-files etc.). Most importantly, using Python for AutoCAD allows you to tap into functionalities that are beyond AutoCAD. You can use that to develop custom applications for project or client specific problems.

Links to related AutoCAD automatization content

If you want to learn more about AutoCAD automatization with Python then I suggest you have a look at some of our other pyautocad and pywin32 related articles. Here is a list with some of them:

You May Also Like

Leave a Reply

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.