• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
blog.draftsperson.net

blog.draftsperson.net

the art of technical drawing

blog.draftsperson.net

PORTLOCK LISP: Lock Every Viewport on Every Layout

August 3, 2026

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

  1. Load the routine with APPLOAD, or put it on your support file search path.
  2. Type PORTLOCK.
  3. 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

NamePortLock — lock every viewport on every layout in the drawing
DownloadPortLock.lsp — 3.9 KB, plain AutoLISP source. Downloads directly; no zip to unpack.
TypeAutoCAD AutoLISP routine
CommandPORTLOCK
Requiresnothing beyond a CAD platform with AutoLISP.
Source size3.9 KB, 100 lines
Error handlingYes — a *error* handler restores every system variable it changed, on cancel as well as on error.
UndoThe whole operation is wrapped in a single undo group, so one U reverses all of it.
CompatibilityAutoCAD (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.
AuthorYZ, August 2026
LicenceFree 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

Filed Under: AutoLISP Routines

Primary Sidebar

Subscribe to our Youtube Channel

Post CAD drafting jobs on Freelancer.com. and get some free money to do this.

Categories

  • American Steel Industry (4)
  • AutoCAD Articles & Reference (30)
  • AutoCAD Bugs & Problems (19)
  • AutoCAD Tips (29)
  • AutoCAD Tutorials (54)
  • AutoLISP Routines (328)
  • AutoLISP Tutorials (15)
  • CAD Standards (7)
  • Civil 3D (7)
  • Civil Drafting (4)
  • Dimensions (2)
  • Drafting Funnies (71)
  • Drafting History (9)
  • Drafting Standards (84)
  • Electrical Drafting (2)
  • General IT reference (7)
  • Geometry (15)
  • GIS (2)
  • Hatch Patterns (12)
  • Office Life Hacks (3)
  • PT (1)
  • Revit Tutorials (54)
  • Steel Detailing (14)
  • Structural Drafting (26)
  • Technical Dictionary (61)
  • Useful Website Links (19)

Footer

Free downloads

  • Free AutoLISP routines
  • Free hatch patterns
  • SHX fonts & text styles
  • Numbering LISP collection
  • ISO 3098B font

Reference charts

  • AWS weld symbols chart
  • Steel detailing chart
  • Hole & slot sizes
  • Bolt edge distance
  • ANSI & ARCH paper sizes
  • How to fold an A1 drawing

Useful links

  • CAD blocks (DWG)
  • Revit families
  • structuraldrafter.com
  • cad-corner.com
  • About
  • Privacy policy

Provided for free with no warranty · Log in