A locked viewport cannot have its zoom scale changed by accident. PORTLOCK locks every one of them, on every layout, in a single command. This is the cheapest piece of drawing hygiene there is.
What PortLock does
Once a sheet is set up at 1:50, locking the viewport means an absent-minded scroll wheel while inside it can no longer quietly rescale the drawing — which is the failure that produces a sheet labelled 1:50 and plotted at something else, and nobody notices until somebody scales off it.
Model space has no viewports to lock and is skipped automatically, since layoutlist returns only paper space layouts.
How to use it
- Load the routine with
APPLOAD, or put it on your support file search path. - Type
PORTLOCK. - Every viewport on every layout is locked. You end up back on the tab you started on.
How it works
The routine walks the layouts by changing CTAB, the current tab.
That is why the error handler matters more here than usual. If it failed part way through without one — and a layout containing no viewports at all is enough to upset the -VPORTS command — you would be dumped on whichever random layout the loop had reached, with no obvious way to tell how far it had got.
The handler always returns you to the tab you started on, whether the run finished, failed or was cancelled.
Notes and limits
- It locks, it does not unlock. Unlock individually when a viewport genuinely needs rescaling.
- Model space is skipped automatically.
- You always end up back where you started, even if the run is interrupted.
- Run it before issuing. Locking after a sheet is set up is what protects the scale it was set up at.
Download and details
| Name | PortLock — lock every viewport on every layout in the drawing |
| Download | PortLock.lsp — 3.9 KB, plain AutoLISP source. Downloads directly; no zip to unpack. |
| Type | AutoCAD AutoLISP routine |
| Command | PORTLOCK |
| Requires | nothing beyond a CAD platform with AutoLISP. |
| Source size | 3.9 KB, 100 lines |
| Error handling | Yes — a *error* handler restores every system variable it changed, on cancel as well as on error. |
| Undo | The whole operation is wrapped in a single undo group, so one U reverses all of it. |
| Compatibility | AutoCAD (any release with AutoLISP), BricsCAD, ZWCAD, GstarCAD, ProgeCAD and other IntelliCAD-based platforms. AutoCAD LT needs a LISP enabler. No .NET, no ObjectARX, no installer. |
| Author | YZ, August 2026 |
| Licence | Free to use, supplied “as is” with no warranty. |
References
- Drawing scale chart — the scale a locked viewport is protecting
- PINOBJECT LISP — protecting individual objects rather than viewports
- VIEWFRAME LISP — working with viewport frames
- More free AutoLISP routines on this site
- Wisey’s Steel Shapes — free structural steel section drawing program