AutoLISP Tutorial Drawing Statistics in AutoCAD
AutoLISP Tutorial Drawing Statistics in AutoCAD
com
Tuto
This AutoLISP Tutorial: Drawing Statistics in AutoCAD serves as a stepping stone for those eager
to harness the potential of custom scripts to automate and enhance their CAD workflows. Dive
deep into a programmatic approach to fetch drawing statistics, understand object type
distributions, layers, and block instances.
If you’re a budding CAD professional or an enthusiast wanting to tailor AutoCAD to your needs,
this guide is your passport to a more efficient drafting experience. Harness the power of AutoLISP
and make AutoCAD truly your own!
Key Takeaways
1. Understanding AutoLISP: Grasp the foundational elements of the AutoLISP programming
language, setting the stage for advanced CAD customization.
2. Program Breakdown: Familiarize yourself with the nuts and bolts of the DWGSTATS program,
gaining insights into how to extract drawing statistics.
3. Real-world Application: Learn how to implement this program in your projects, making
information retrieval efficient and hassle-free.
4. Customization Potential: Recognize the versatility of AutoLISP, opening doors to endless
possibilities in terms of drawing automation and customization.
Creating an AutoLISP program to provide a summary of objects, layers, block instances, etc. in an
AutoCAD drawing can be a bit complex depending on how detailed the summary needs to be.
Here’s a simple program to getHOME
started: COURSE TUTORIALS BLOG DOWNLOAD SUBSCRIBE
(defun C:DWGSTATS (/ sset count objtype obj data layers blocks)
;; Select all entities in the drawing
(setq sset (ssget “X”))
(setq count (sslength sset))
(setq data (list))
(setq layers ‘())
(setq blocks ‘())
;; Check and collect block data if object type is INSERT (block instance)
(if (= objtype “INSERT”)
(if (not (member (cdr (assoc 2 (entget obj))) blocks))
(setq blocks (cons (cdr (assoc 2 (entget obj))) blocks))
)
)
;; Increment the count for this object type in the data list
(if (assoc objtype data)
(setq data (subst (cons objtype (1+ (cdr (assoc objtype data)))) (assoc objtype data) data))
(setq data (cons (cons objtype 1) data))
)
)
Note: This is a basic program, and there are many ways to expand upon it. You can extract more
details, such as dimensions, texts, etc. Adjust and expand the code as needed!
Step-by-step Explanation:
Program Initialization
(defun C:DWGSTATS (/ sset count objtype obj data layers blocks)
defun: This command defines a new function in AutoLISP. The name of our
function/command is DWGSTATS.
The / symbol: Variables following this symbol are local to the function. This means their
values won’t interfere with any variables outside the function with the same names.
Initialization of Variables
(setq count (sslength sset)) (setq data (list)) (setq layers ‘()) (setq blocks ‘())
Here, we initialize and set various variables:
count: The number of objects in the selection set.
data: An empty list that will store data about the types and counts of objects.
layers & blocks: Empty lists to store unique layers and blocks.
HOME COURSE TUTORIALS BLOG DOWNLOAD SUBSCRIBE
Loop Through the Selection Set
(repeat count
The repeat function loops a set of commands a specified number of times. We’re looping
for each object in our selection set.
Lessons
Comparisons
Boolean Operations