AutoCAD VBA Add-In: Calculate Polylines Length & Area

Share this

May 27, 2013

AutoCAD VBA - Calculate Polylines Length & Area
At the beginning of April, I posted an Excel VBA code for creating a polyline in AutoCAD using coordinates from an Excel workbook. In the comments sections of that post, Jake asked me to do almost the opposite procedure. So, below you will find an AutoCAD VBA add-in that can:
  • Calculate the length of all polylines, as well as the area of all closed polylines from a selected layer.
  • Calculate the length of all polylines, as well as the area of all closed polylines from all the layers of the current drawing.
  • Export the results to a new Excel workbook.
In general, I think that this add-in might be quite useful for civil engineers, as well as for anyone who uses polylines at his/her drawings and needs a way to calculate their length and area quickly.

I should point out that the add-in calculates the area from closed polylines only. So, this means that when the polyline was drawn, the closed option should have been used at the end. If a polyline was left opened or it was manually closed (by linking the last point with the first point), then the code will not take its area into account. However, its length will be measured. The video below has an example of polylines who look closed, but they aren’t.

How to use it
  1. Open your AutoCAD.
  2. In command line write VBAMAN.
  3. Press the Load button in the menu that will appear.
  4. At the browser find the file Polyline Area.dvb.
  5. Choose the Enable Macros button and then press the Macros button.
  6. At the macros menu, press the Run button. A form will appear (see figure above).
  7. In the form you have two choices: you can either select a layer from the combo box, or you can check the checkbox to loop through all the layers of the current drawing. In both cases press the Calculate Length & Area button after. The list box will be populated with information from all the polylines of the selected layer or all the layers of the drawing. Two text boxes below the list box will contain the total length and the total area.
  8. Finally, if you press the Export To Excel button, a new workbook will be created and will contain all the results of the list box to be further processed (for reporting purposes).
If you have closed the form and want to re-use it, you don’t have to reload the file. You can just write VBARUN at the command line and continue the procedure from step 6. If you have AutoCAD 2010 or a newer version, then you will have to download the VBA module from Autodesk, since from 2010 VBA is not installed with AutoCAD.

Demonstration video

The short video below demonstrates the use of add-in in practice. By the way, in this video, you will listen for the time my terrible voice!!! I know that I sound like a robot, but, I hope that at least you can understand what I am trying to say… 

Download it from here

The file was tested with AutoCAD 2013, but it will probably work in either older or newer AutoCAD versions.

Read also

Draw A Polyline In AutoCAD Using Excel VBA
AutoCAD – Calculate The Total Length Of Lines
AutoCAD – Total Length Of Lines Per Layer

Page last modified: September 29, 2021

Christos Samaras

Hi, I am Christos, a Mechanical Engineer by profession (Ph.D.) and a Software Developer by obsession (10+ years of experience)! I founded this site back in 2011 intending to provide solutions to various engineering and programming problems.

  • Thank you so much for providing this much good work. Please keep posting stuff like this.. 🙂 It saved my 8 hours of work and I am done with is in just half hour.

  • Dear Christos,
    I’m Marco, electrical engineer and reasearcher. I worked a lot with Excel and VBA but it’s the first time that I meet VBA for Autocad. In Excel I’ve made a very big energy tool that you can download here for free following the link down in the message.
    I appreciated very much your work, and I’d like to make some upgrades to your software without commercial revenues. So, if you are interested to share your code in some form of collaboration, you can write me to the e-mail below.
    Thank you very much.

  • I can not load my cad file because it says *.dvd file name from your video

  • {"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
    Add Content Block