[AutoCAD LISP] Distribute and Arrange Objects Equally Instantly (EQA.lsp)
Manually spacing out objects in AutoCAD—whether they are blocks, text, or
geometric shapes—is an absolute chore. Typically, you have to use the DIVIDE
or MEASURE commands, draw temporary reference lines, or pull out a
calculator to figure out the exact spacing. It wastes precious drafting time
and leaves room for annoying human errors.
The EQA (Equal Arrange) LISP completely eliminates this hassle. It
automatically calculates the perfect 1:1:1 equal spacing for any number of
objects within a boundary you specify. Whether you need them lined up
horizontally or vertically, it detects the orientation and centers them
instantly.
Why You Should Use the 'EQA' LISP
- Zero Calculations Required: No more manual math. The LISP counts the selected objects and divides the space perfectly.
- Smart Orientation Detection: If your bounding box is wider than it is tall, it arranges objects horizontally. If it’s taller, it arranges them vertically.
- Automatic Center Alignment: It doesn't just space them out; it aligns the center points of all objects precisely along the centerline of the boundary.
- Visual Reference: It automatically draws a subtle reference line across your boundary so you can easily verify the alignment area.
How It Works (Step-by-Step Guide)
- Load the LISP: Load the EQA.lsp file into your AutoCAD session.
- Run the Command: Type EQA in the command line and press Enter.
- Select Objects: Select all the objects (blocks, lines, text, etc.) you want to arrange, then press Enter.
- Define the Boundary: * Click to specify the first corner of your alignment boundary.
- Click to specify the opposite corner to form a rectangular bounding area.
-
Instant Result: The LISP will instantly sort and distribute your objects
with perfect, equal spacing, and add a center guide line.
Wrapping Up
If you frequently work on layouts, schematic diagrams, or any design that requires neat, uniform spacing, the EQA LISP is going to save you hours of tedious work. Give it a try, add it to your startup suite, and watch your drafting efficiency skyrocket!
The LISP Code
(defun c:EQA ( / acadObj doc space ss p1_ucs p2_ucs p1 p2 minX maxX minY maxY totalW totalH cX cY cnt i ent vla-obj minpt maxpt cenX cenY items spacing targetX targetY startPt endPt lineObj )
(vl-load-com)
(setq acadObj (vlax-get-acad-object)
doc (vla-get-activedocument acadObj)
space (vla-get-modelspace doc)
)
(princ "\nSelect objects to arrange: ")
(setq ss (ssget))
(if (and ss (> (sslength ss) 0))
(progn
(setq p1_ucs (getpoint "\nSpecify first corner of boundary: "))
(if p1_ucs
(progn
(setq p2_ucs (getcorner p1_ucs "\nSpecify opposite corner of boundary: "))
(if p2_ucs
(progn
(vla-StartUndoMark doc)
(setq p1 (trans p1_ucs 1 0)
p2 (trans p2_ucs 1 0)
minX (min (car p1) (car p2))
maxX (max (car p1) (car p2))
minY (min (cadr p1) (cadr p2))
maxY (max (cadr p1) (cadr p2))
totalW (- maxX minX)
totalH (- maxY minY)
cX (/ (+ minX maxX) 2.0)
cY (/ (+ minY maxY) 2.0)
)
(setq cnt (sslength ss) i 0 items nil)
(repeat cnt
(setq ent (ssname ss i)
vla-obj (vlax-ename->vla-object ent))
(vla-getboundingbox vla-obj 'minpt 'maxpt)
(setq minpt (vlax-safearray->list minpt)
maxpt (vlax-safearray->list maxpt)
cenX (/ (+ (car minpt) (car maxpt)) 2.0)
cenY (/ (+ (cadr minpt) (cadr maxpt)) 2.0)
)
(setq items (cons (list cenX cenY vla-obj) items))
(setq i (1+ i))
)
(if (> totalW totalH)
(progn
(setq items (vl-sort items '(lambda (a b) (< (car a) (car b)))))
(setq spacing (/ totalW (1+ cnt)))
(setq i 1)
(foreach item items
(setq vla-obj (caddr item)
targetX (+ minX (* i spacing))
)
(vla-move vla-obj (vlax-3d-point (list (car item) (cadr item) 0.0)) (vlax-3d-point (list targetX cY 0.0)))
(setq i (1+ i))
)
)
(progn
(setq items (vl-sort items '(lambda (a b) (> (cadr a) (cadr b)))))
(setq spacing (/ totalH (1+ cnt)))
(setq i 1)
(foreach item items
(setq vla-obj (caddr item)
targetY (- maxY (* i spacing))
)
(vla-move vla-obj (vlax-3d-point (list (car item) (cadr item) 0.0)) (vlax-3d-point (list cX targetY 0.0)))
(setq i (1+ i))
)
)
)
(setq startPt (vlax-3d-point p1)
endPt (vlax-3d-point p2)
lineObj (vla-addline space startPt endPt)
)
(vla-put-color lineObj 252)
(vla-EndUndoMark doc)
(princ "\nObjects arranged successfully and center line added.")
)
)
)
)
)
)
(princ)
)

Post a Comment