[Search tip detail and code files using keywords, tip number, author name, etc ]
 
Lock and Unlock Viewports
Tip# 4242 By Jessica Confer On 27-Jan-2014
4
Rated By 2 users
Categories : Viewports, Paper Space
Software type : AutoCAD 2014
Rename File To : No Files to download.
Use these functions to lock and unlock viewports with ease.

Like many AutoCAD users, tip contributor Jessica Confer likes to work inside of locked model space viewports within layouts.

"For example, there are times when you need to unlock the viewport for repositioning. Here are a couple of functions that allow you to lock and unlock viewports with ease. Use VL to lock viewports and VUL to unlock them."

Viewport Lock – Keyboard Command VL
    ;;LOCKS VIEWPORT
    (defun c:vl (/ vp1)
     (setq vp1 (ssget))
     (command "mview" "l" "on" vp1 ""))

Viewport Unlock – Keyboard Command VUL
    ;;UNLOCKS VIEWPORT
    (defun c:vul (/ vp2)
      (setq vp2 (ssget))
      (command "mview" "l" "off" vp2 ""))

Notes from Cadalyst tip reviewer R.K. McSwain: Locking viewports makes working on drawings much easier, and these two shortcut LISP functions are going to make it even easier for us. Thanks Jennifer.

 

Average Rating:
4


User comments
Comment by Cardenas,J. Raul
Posted on 2014-01-27 18:07:03
Great shortcuts!!! I love them. Also, don't forget to double click on the viewport to work within, whether viewport is locked or not and last but not least, right click on the viewport for the option "Display Locked" Yes or No.
Comment by Sanders,Richard
Posted on 2014-01-29 18:35:54
Here is an enhanced version of a routine from the 'olden' days that I have used for years. Copy the following into Notepad; rename as "ViewPortLock.lsp" Then follow the directions to add the appropriate lines below into your acaddoc.lsp file as well, and it will auto-run upon opening each drawing. Note that VPL will autolock ALL viewports in ALL tabs, while VPU only Unlocks the viewports in the CURRENT tab. ;;; ViewPortLock - version edited 2008 by R.A.Sanders ;;; This routine provides the following shortcuts: ;;; VPL for locking all viewports in the current drawing ;;; *Locked viewports are changed to AMBER (color=30) ;;; VPU for UN-locking all viewports in the current tab ;;; *UN-locked viewports are changed to RED (color=1) ;;; ;;; I would add that the (vl-load-com) command must first be 'loaded' ;;; when using newer versions of ACAD (after v2008 or so, I think) ;;; in order for some LISP routines to work correctly. ;;; *This apparently ensures compatibility with newer ACAD versions for Visual LISP ;;; I have added the "(vl-load-com)" command to my custom acaddoc.lsp file ;;; so that it does not need to be added to every .lsp command file. ;;; ;;; *found in the folder c:Program FilesAutodeskAutoCAD 2012 - EnglishSupport ;;; ;;; --- INSIDE the file "acaddoc.lsp" ADD the following lines ---------- ;;; --- Obviously, remove the ";;; " before each line ----------------- ;;; (vl-load-com) ;;; ; *This ensures compatibility with newer ACAD versions for Visual LISP ;;; (load "ViewPortLock.lsp") ;;; ; *This loads the VPL and VPU commands to lock and unlock viewports ;;; (C:VPL) ;;; ; *This should 'run' the command "VPL" upon opening each Drawing, which ;;; ; will ensure that regardless of whether others have inadvertantly ;;; ; booby-trapped the Drawing you are opening with unlocked viewports, you ;;; ; will have the comfort of knowing that at the beginning of each editing ;;; ; session you have, all of the viewports in all paperspace tabs will be ;;; ; initially LOCKED for your safety. ;;; -------------------------------------------------------------------- ;;; ;;; --- COMMAND HELP --- (defun C:VP? () (textscr) (princ " --- VPU and VPL HELP --- ViewPortLock provides these shortcuts: VPL = Lock all viewports in current drawing Locked viewports are changed to AMBER (color=30) VPU = Unlock all viewports in current layout tab Locked viewports are changed to RED (color=1) ") (princ) ) ;;; ;;; --- CONFIRM VISUALLY THAT THE ROUTINE HAS BEEN LOADED --- ;;; (princ " --- ViewPortLock.LSP has been loaded Type <VP?> for HELP ") ;;; ;;; ;;; --- LOCK VIEWPORTS IN ALL LAYOUT TABS --- (defun c:VPL (/ THISTAB VPLST VPS) (setq THISTAB (getvar "CTAB")) (foreach LAYOUT (layoutlist) (setvar "CTAB" LAYOUT) (setq VPLST (ssget "x" (list (cons 0 "viewport")))) (setq c -1) (if VPLST (repeat (sslength VPLST) (setq VPS (cdr (car (entget (ssname VPLST (setq c (1+ c))))))) (setq VLAOBJ (vlax-ename->vla-object VPS)) (vlax-put-property VLAOBJ 'Color 30) )) (command "mview" "lock" "on" VPLST "") ) (setvar "CTAB" THISTAB) (princ) ) ;;; ;;; --- UNLOCK VIEWPORTS IN CURRENT LAYOUT TAB ONLY --- (defun c:VPU (/ VPLST THISTAB VPS) (setq THISTAB (getvar "ctab")) (setq VPLST (ssget "x" (list (cons 0 "viewport") (cons 410 THISTAB)))) (setq c -1) (if VPLST (repeat (sslength VPLST) (setq VPS (cdr (car (entget (ssname VPLST (setq c (1+ c))))))) (setq VLAOBJ (vlax-ename->vla-object VPS)) (vlax-put-property VLAOBJ 'Color 1) )) (if (= (getvar "ctab") "Model") (princ " --- Command not allowed in Modelspace Tab ---") (command "mview" "lock" "off" VPLST "") ) (princ) ) ;;;
Comment by Ridenhour,Mark
Posted on 2014-02-04 09:31:13
Why not just click the LockUnlock Viewport button in the Drawing Status Bar Menu at the bottom of the page? It pops up when you select the viewport. Also a good place to set the Scale. Just make sure it's turned on. There is a little drop-down arrow on the right where you can select the buttons that show up when appropriate.
Comment by Confer,Jessica
Posted on 2014-02-04 11:13:19
"Why not just click the LockUnlock Viewport button in the Drawing Status Bar Menu at the bottom of the page? It pops up when you select the viewport. Also a good place to set the Scale. Just make sure it's turned on. There is a little drop-down arrow on the right where you can select the buttons that show up when appropriate. " Some CAD users do not use buttons very often if not at all. I find that drafting is much faster when using keyboard commands most of the time. Jessica Confer
Comment by Marquez,Eric
Posted on 2014-04-08 11:25:33
A couple of keystrokes is faster than navigating your mouse around the screen and clicking buttons! Thanks Jessica!


Log In