Last updated July 28, 2026
VPGRID draws a survey coordinate grid over a viewport. You select a viewport in a layout, give it a grid interval in metres, and it lays a border around the viewport, tick marks where each grid line meets that border, easting and northing labels against every tick, and small crosses at each grid intersection inside.
It is a more considered piece of work than its one-line description suggests. Three things in particular set it apart from the usual approach of drawing a grid in model space and hoping.
Why it works where a model-space grid does not
It reads the viewport, not the drawing. The routine pulls the viewport’s own data — its width and height on the sheet, its scale, its centre point in world coordinates and its twist angle — and works out from that exactly which patch of the survey the viewport is showing. The grid it draws is therefore correct for that viewport and no other.
It handles rotated viewports. This is the part that matters on a site plan turned to suit the sheet. Because it knows the twist angle, it works out which grid lines cross which edge of the rotated viewport frame, places the tick on the right edge, and rotates the label to stay readable — flipping the text through 180 degrees and swapping its justification when the rotation would otherwise leave it upside down.
Everything is sized in paper space. The border ticks, the centre crosses and the text height are all defined as millimetres on the sheet and then divided by the viewport’s scale factor, so a grid over a 1:200 viewport and a grid over a 1:1000 viewport come out the same size on paper. Change the viewport scale and rerun it, and the annotation stays right.
What it draws, and where
Three layers are created and used, so the whole grid can be frozen or plotted separately from your drawing: GRID_BORDER for the frame, GRID_TICKS for the tick marks and centre crosses, and GRID_TEXT for the labels. Labels are written as the coordinate value followed by E for eastings and N for northings, in the ISOCP text style, which the routine creates if your drawing does not already have it.
Run it a second time on a viewport that already has a grid and it notices, offering Append, Replace or eXit. Replace deletes the existing grid entities before drawing the new one; the default is Replace.
The built-in sizes are 20 units for the border ticks, 10 for the centre crosses and 2.5 for the text height, all in paper space, and the layers are made in colour 7. Those are set as plain numbers near the top of the file, so changing them to suit your office standard is a two-minute edit.
One latent bug worth knowing
There is a fault in the code that only fires in one specific circumstance: when the extent of the visible area divides exactly by your grid interval, so the last grid line falls precisely on the viewport edge. In that case the routine reaches a line that was meant to subtract one from a counter but was mistyped, and AutoCAD stops with a “bad function” error.
Most of the time your viewport edges land on arbitrary coordinates and it never comes up. If it does bite, the workaround is trivial — nudge the viewport a fraction, or use a slightly different grid interval — and the actual fix is a one-character correction in two places.
Also present but harmless: an unfinished function that would have offered a choice between a full grid and ticks only. It is never called, and the file works without it.
Command reference
The file defines a single command, VPGRID. It must be run from a layout, not from model space, because it works on a paper-space viewport object.
How to load it
Unzip Vpgrid.zip and load vpgrid.lsp with APPLOAD, or add it to the Startup Suite. There are no support files, though the ISOCP shape file needs to be available for the text style it creates. Our AutoLISP guide covers loading.
Step-by-step usage
- Open the layout, and make sure the viewport is set to its final scale and position. Rerunning after a scale change is easy, but getting it right first saves a step.
- Type VPGRID. If a grid already exists you are asked Append, Replace or eXit.
- At “Select viewport:” click the viewport frame. Pick anything else and it tells you so and asks again.
- At “Grid interval (m):” enter the spacing in metres — 10, 25, 100, whatever suits the scale.
- The border, ticks, labels and centre crosses are drawn. Layer 0 is left current when it finishes.
Compatibility notes
The file carries no date or author. It reads viewport extended data and builds entities directly, which is long-standing AutoLISP practice, and it drives the command-line LAYER command — so written-for rather than tested-on, but nothing in it looks release-specific.
It is plain AutoLISP with no dialog boxes and no Express Tools calls, so nothing in it requires the full product; LT users on LT 2024 or later, the release that brought AutoLISP to LT, should be able to run it. See what runs on AutoCAD LT. It creates layers and a text style and draws a lot of entities, so try it on a copy of the sheet first.
Download
| Name: | VPGRID |
| Description: | Places a grid in a Viewport with co-ordinates. |
| Type: | AutoCAD AutoLISP Routine |
| Author: | Anon |
| File Size: | 3 Kb |
| Cost: | Free |
| Worked on: | AutoCAD |
| Download File: | Vpgrid.zip |
Related routines
- ImportXYZ — bring the survey coordinates into the drawing the grid annotates.
- COGO bearing and distance label — label the boundary lines inside that grid.
- BANK — batter and slope symbols for the same site plans.