AutoCAD automation has been discussed several times in this blog. Various add-ins and VBA codes have been presented, mainly for drawing polylines and measuring lines’ length. Below you will find another useful VBA add-in that automatically lists all the blocks that exist in the active drawing. The add-in is, in reality, a form, containing a list box control, a text box and three buttons. When the Count Blocks button is pressed, the code loops through all the blocks of the active drawing. If a block is found, is added to the list box control. Moreover, in the text box, the total number of blocks will appear.
How to use it
- Open AutoCAD.
- In the command line write VBAMAN.
- Press the Load button in the menu that will appear.
- Use the browser window to find and open the Count Existing Blocks.dvb file.
- Choose the Enable Macros button and then press the Macros button.
- At the macros menu, select the CountBlocks macro and press the Run button. A form will appear (see the figure above).
- Press the Count Blocks button and the list box will be populated with all the blocks that exist in the active drawing. The text box below the list box will contain the total blocks.
- Finally, if you press the Export To Excel button, a new workbook will be created containing all the data from the list box and the text box.
- If you have closed the form and want to re-use it you don’t have to reload the file. You can simply write VBARUN at the command line and continue the procedure from step 6.
Note: If you have AutoCAD 2010 or a newer AutoCAD version, download the VBA module from Autodesk’s site before using this add-in.
The short video below shows you how to load and use the add-in.
There are two different “manual” solutions regarding block counting. The first one involves the command BCOUNT, while the other the Data Extraction tool (more complicated solution). Below you will find some guidelines about how to “manually” count blocks in AutoCAD (without using the above tool).
Using the BCOUNT (block count) command
- In the command line write BCOUNT.
- Select an area that contains the blocks you want to count.
- Press Enter (or click the right button of your mouse). In the command line window, the block names and the instances will appear.
- Select and copy the results to a new workbook.
Using the Data Extraction tool
- In the command line write EATTEXT. The data extraction wizard will start, containing 8 pages/steps.
- In the form that will appear choose the Create a new data extraction radio button and press the Next button (page 1 of 8).
- Select the folder where you want to save the new .dxe file, give it a meaningful name and press the Save button.
- Choose the Drawings/Sheet set radio button, check the Include current drawing checkbox and press the Next button (page 2 of 8).
- Uncheck the Display all object types checkbox, choose the Display blocks only radio button, check the Display objects currently in-use only checkbox and press the Next button (page 3 of 8).
- There are various properties you can extract by checking the appropriate checkbox. For the particular example, use the Category filter to uncheck all the categories except the General category and press the Next button (page 4 of 8).
- Leave all the checkboxes enabled and press the Next button (page 5 of 8).
- Check the Output data to external file checkbox and specify the location, the type and the name of the output (.xls, .csv, .mdb, .txt) file. Press the Next button (page 6 of 8).
- Finally, press the Finish button (page 8 of 8). Then, find the output file and open it. It would probably look like the image below.
Up until now, you learned 2 + 1 different ways to count the blocks in a drawing, so you can choose the solution that best fits your needs!
The file was created and tested with AutoCAD 2013, but it will probably work in either older or newer AutoCAD versions.
Insert Blocks In AutoCAD Using Excel & VBA
AutoCAD VBA Add-In: Calculate Polylines Length & Area
Thanks for pointing out the error.
I just corrected the file, so it should work now.
I tested it on AutoCAD 2021 without a problem.
hii iam using autocad version 2021 and when iam running this macro iam getting error like object doesnt support this property will you help me out with it