Message 1 of 3
AutoCAD LT Automatic Layouts & Viewports
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi! I managed to make a LISP for automatic layout and viewport creation that works in AutoCAD LT 2026.1 (Won't run on full AutoCAD).
You can change the Matrix here:
(setq pairs
'(
(1 0) (2 0)
(0 1) (1 1) (2 1)
(0 2) (1 2) (2 2)
(1 3)
)
)
And Delta X / Delta Y here;
(setq dx (* 42.0 (car p)))
(setq dy (* 42.0 (cadr p)))Usage:
1) Must run from a master layout, which will be copied and have it's viewport shifted by dx and dy, according to the Matrix scheme.
2) Requires AutoCAD LT version 2026.1 (August 2025 Update).
Notes:
3) Will not run on full AutoCAD, because the DXF internal codes of the viewport-type entity differ in LT (Viewport witdh and lenghts are stored in DXF codes 40 and 41 in AutoCAD LT, while in full AutoCAD they are stored in DXF codes 41 and 42). For full AutoCAD there allready exist other lisps that will simply change the model coordinates for each Viewport.
4) I had to do a double stretch in each direction followed by a move in opposite directions, because in LT the Viewport model coordinates are locked (you cannot change them or pan inside the viewport window, programatically).
5) I used ChatGPT to help code, since my LISP knowledge is very poor.
6) I attach a simple dwg example, for testing purposes.
Full Code:
;; ========================================================
;; Helper: stretch and counter-move viewport
;; ========================================================
(defun VM-BATCH-STRETCH (layout dx dy / ss en data width height hw hh cX cY origX origY newX newY deltaX deltaY p1 p2)
(command "_LAYOUT" "_S" layout)
(command "_REGEN")
(setq ss (ssget "X" (list (cons 0 "VIEWPORT") (cons 410 layout))))
(if (and ss (> (sslength ss) 0))
(progn
(setq en (ssname ss 0))
(setq data (entget en))
(setq origX (car (cdr (assoc 10 data))))
(setq origY (cadr (cdr (assoc 10 data))))
(setq width (cdr (assoc 40 data)))
(setq height (cdr (assoc 41 data)))
(setq hw (/ width 2.0))
(setq hh (/ height 2.0))
(setq cX origX cY origY)
;; Horizontal stretch
(if (/= dx 0)
(progn
(setq p1 (list (+ cX hw) (- cY hh)))
(setq p2 (list (+ cX hw) (+ cY hh)))
(vl-cmdf "_STRETCH" "_C" p1 p2 "" p1 (list (+ (car p1) dx) (cadr p1) 0))
(command "_REGEN")
(setq data (entget en))
(setq width (cdr (assoc 40 data)))
(setq cX (car (cdr (assoc 10 data))))
(setq hw (/ width 2.0))
(setq p1 (list (- cX hw) (- cY hh)))
(setq p2 (list (- cX hw) (+ cY hh)))
(vl-cmdf "_STRETCH" "_C" p1 p2 "" p1 (list (+ (car p1) dx) (cadr p1) 0))
(command "_REGEN")
)
)
;; Vertical stretch
(if (/= dy 0)
(progn
(setq data (entget en))
(setq height (cdr (assoc 41 data)))
(setq cY (cadr (cdr (assoc 10 data))))
(setq hh (/ height 2.0))
(setq p1 (list (- cX hw) (+ cY hh)))
(setq p2 (list (+ cX hw) (+ cY hh)))
(vl-cmdf "_STRETCH" "_C" p1 p2 "" p1 (list (car p1) (+ (cadr p1) dy) 0))
(command "_REGEN")
(setq p1 (list (- cX hw) (- cY hh)))
(setq p2 (list (+ cX hw) (- cY hh)))
(vl-cmdf "_STRETCH" "_C" p1 p2 "" p1 (list (car p1) (+ (cadr p1) dy) 0))
(command "_REGEN")
)
)
;; Counter-move
(setq data (entget en))
(setq newX (car (cdr (assoc 10 data))))
(setq newY (cadr (cdr (assoc 10 data))))
(setq deltaX (- origX newX))
(setq deltaY (- origY newY))
(vl-cmdf "_MOVE" en "" '(0 0 0) (list deltaX deltaY 0))
(command "_REGEN")
)
)
)
;; ========================================================
;; Main command: clone layouts and apply stretches
;; ========================================================
(defun c:VM-LAYOUTA01 (/ layoutName layouts dxdy newLayout layoutCounter dx dy i)
(vl-load-com)
(setq layoutName "VM01")
(command "_LAYOUT" "_S" layoutName)
(setq pairs
'(
(1 0) (2 0)
(0 1) (1 1) (2 1)
(0 2) (1 2) (2 2)
(1 3)
)
)
(setq layouts (list layoutName))
(setq dxdy (list (list 0 0)))
(setq layoutCounter 2)
(foreach p pairs
(setq newLayout (strcat "VM" (if (< layoutCounter 10) "0" "") (itoa layoutCounter)))
(command "-LAYOUT" "COPY" layoutName newLayout "")
(setq dx (* 42.0 (car p)))
(setq dy (* 42.0 (cadr p)))
(setq layouts (append layouts (list newLayout)))
(setq dxdy (append dxdy (list (list dx dy))))
(setq layoutCounter (1+ layoutCounter))
)
(setq i 0)
(while (< i (length layouts))
(setq newLayout (nth i layouts))
(setq dx (car (nth i dxdy)))
(setq dy (cadr (nth i dxdy)))
(VM-BATCH-STRETCH newLayout dx dy)
(setq i (1+ i))
)
(princ "\nAll layouts cloned and viewport stretches applied.\n")
(princ)
)