RecipesEdit in bulk
How do I rotate and align the viewport on every plan sheet to its rectangle in AutoCAD?
Type "Layer SHEET-WINDOW has one rectangle per sheet, labelled SHEET 1 to SHEET 12, and layouts PLAN-01 to PLAN-12 have one viewport each. Make each layout's viewport show its rectangle: centred, long edge horizontal with the road running left to right in sheet order, zoomed to fit, then lock it". cadssistant reads the rectangles and their labels from model space, works out each one's centre, the angle of its long edge and its short side, and sets every viewport in one pass: centred on its rectangle, twisted so that edge is horizontal and the sheets read in order, scaled so the rectangle fills the viewport's height, and locked. You don't open a single layout. The reply lists each layout with the point it is centred on, its twist and its scale, so a sheet that got the wrong rectangle shows up at once. By hand it is ALIGNSPACE, or a UCS and PLAN inside every viewport, one sheet at a time; the routine below does one sheet per run.
Checked 2026-10-30 · one of the tasks cadssistant's models are benchmarked on
Layer SHEET-WINDOW has one rectangle per sheet, labelled SHEET 1 to SHEET 12, and layouts PLAN-01 to PLAN-12 have one viewport each. Make each layout's viewport show its rectangle: centred, long edge horizontal with the road running left to right in sheet order, zoomed to fit, then lock it
What cadssistant does
- Reads every rectangle on the sheet-window layer and the label inside each, so SHEET 1 to SHEET 12 are matched to their layouts by name, not by guess.
- Works out each rectangle's centre, the angle of its long edge and its short side; the direction from one sheet's centre to the next decides which way is left to right.
- Sets all the viewports in one pass: centred on the rectangle, twisted so the long edge is horizontal, the short side fitted to the viewport's height, display locked. Your current tab is left as it was.
- Replies with each layout, the model point it is centred on, its twist and its scale, so a wrong pairing is visible without opening the sheets.
The same task in AutoLISP
(defun c:VPAIM ( / doc vp e p0 p1 p2 ctr ang h)
(vl-load-com)
(setq doc (vla-get-ActiveDocument (vlax-get-acad-object))
vp (vla-get-ActivePViewport doc)
e (car (entsel "\nPick the sheet rectangle: "))
p0 (vlax-curve-getPointAtParam e 0)
p1 (vlax-curve-getPointAtParam e 1)
p2 (vlax-curve-getPointAtParam e 2)
ctr (mapcar '(lambda (a b) (/ (+ a b) 2.0)) p0 p2)
ang (if (> (distance p0 p1) (distance p1 p2)) (angle p0 p1) (angle p1 p2))
h (min (distance p0 p1) (distance p1 p2)))
(vla-put-DisplayLocked vp :vlax-false)
(command "_.DVIEW" "" "_TW" (* 180.0 (/ (- ang) pi)) "")
(command "_.ZOOM" "_C" (trans ctr 0 1) h)
(vla-put-DisplayLocked vp :vlax-true)
(princ))One sheet per run: double-click inside the layout's viewport to make it active, type VPAIM, pick that sheet's rectangle. It turns the view so the rectangle's long edge is horizontal, centres on it, fits the short side to the viewport's height and locks the viewport. The rectangle must be a four-corner closed polyline, as RECTANG draws it; if the road comes out running right to left, the rectangle was drawn the other way round, so add 180 to the DVIEW angle.
Good to know
- The rectangles should be ordinary closed polylines, one per sheet, each with a label or a number so the sheets can be matched; say the layer and the layout names if they differ from the example.
- If every sheet comes out turned the other way (the road running right to left), say "turn them all 180 degrees" and every twist is recomputed in one go.
- Civil 3D makes these sheets from the alignment itself; this is for plain AutoCAD, where each sheet's viewport is otherwise aligned by hand.
More in edit in bulk
Command: CADSSISTANT
Works in AutoCAD 2024 and newer on Windows. Free trial, no card, no API key.
Get cadssistant