Toggle Viewport Disply Lock
Toggle Viewport Disply Lock
(OP)
I've got a LISP routine that will toggle a selected viewports "Display Locked" switch.
Please feel free use use/modify to suit your needs.
[code]
; Viewport Display Lock Toggle
; Written by: Kevin petursson
; Aid From: Autodesk Discussion groups
; December 15, 2005
;
; Toggle the "Display Locked" Variable of selected viewports based on the first view port selected
(defun c:vplocktoggle (/ Ename ss )
(princ "\nSelect Viewport...")
;Get selection set, allow only viewports
(setq ss (ssget '((0 . "viewport"))))
(if (IsVpLocked (setq Ename (ssname ss 0)))
;Viewport is locked. Run Unlock commands
(progn
(princ "\nViewport selected is Locked")
;Unlock viewport
(command "mview" "Lock" "OFF" ss "")
;Change viewport color to red to indicate it is Unlocked
(command ".change" ss "" "p" "c" "1" "")
(princ "\nViewport is now Unlocked")
)
;Viewport is unlocked. Run Lock commands
(progn
(princ "\nViewport selected is Unlocked")
;Lock viewport
(command "mview" "Lock" "ON" ss "")
;Change viewport color to ByLayer to indicate it is Locked
(command ".change" ss "" "p" "c" "bylayer" "")
(princ "\nViewport is now Locked")
)
)
(princ)
)
; This function was downloaded from the autodesk discussion groups
; Return: T if locked, Nil otherwise
(defun IsVpLocked (Ename)
(eq 16384 (logand 16384 (cdr (assoc 90 (entget Ename)))))
)
[\code]
Please feel free use use/modify to suit your needs.
[code]
; Viewport Display Lock Toggle
; Written by: Kevin petursson
; Aid From: Autodesk Discussion groups
; December 15, 2005
;
; Toggle the "Display Locked" Variable of selected viewports based on the first view port selected
(defun c:vplocktoggle (/ Ename ss )
(princ "\nSelect Viewport...")
;Get selection set, allow only viewports
(setq ss (ssget '((0 . "viewport"))))
(if (IsVpLocked (setq Ename (ssname ss 0)))
;Viewport is locked. Run Unlock commands
(progn
(princ "\nViewport selected is Locked")
;Unlock viewport
(command "mview" "Lock" "OFF" ss "")
;Change viewport color to red to indicate it is Unlocked
(command ".change" ss "" "p" "c" "1" "")
(princ "\nViewport is now Unlocked")
)
;Viewport is unlocked. Run Lock commands
(progn
(princ "\nViewport selected is Unlocked")
;Lock viewport
(command "mview" "Lock" "ON" ss "")
;Change viewport color to ByLayer to indicate it is Locked
(command ".change" ss "" "p" "c" "bylayer" "")
(princ "\nViewport is now Locked")
)
)
(princ)
)
; This function was downloaded from the autodesk discussion groups
; Return: T if locked, Nil otherwise
(defun IsVpLocked (Ename)
(eq 16384 (logand 16384 (cdr (assoc 90 (entget Ename)))))
)
[\code]





RE: Toggle Viewport Disply Lock
(DEFUN C:VT ()
(COMMAND "LAYER" "THAW" "DEF*,VP*" "")
)
(DEFUN C:VF ()
(COMMAND "LAYER" "FREEZE" "DEF*,VP*" "")
)
(DEFUN C:VL ()
(COMMAND "LAYER" "THAW" "DEF*,VP*" "")
(COMMAND "MVIEW" "LOCK" "ON" "ALL" "")
(COMMAND "LAYER" "FREEZE" "DEF*,VP*" "")
)
(DEFUN C:Vu ()
(COMMAND "LAYER" "THAW" "DEF*,VP*" "")
(COMMAND "MVIEW" "LOCK" "Off" "ALL" "")
(COMMAND "LAYER" "FREEZE" "DEF*,VP*" "")
)
RE: Toggle Viewport Disply Lock
I appriciate the comments.
RE: Toggle Viewport Disply Lock
nice lisp, but You can only use it with american/british versions.
International:
CODE
; Written by: Kevin petursson
; Aid From: Autodesk Discussion groups
; December 15, 2005
;
; Toggle the "Display Locked" Variable of selected viewports based on the first view port selected
(defun c:vplocktoggle (/ Ename ss )
(princ "\nSelect Viewport...")
;Get selection set, allow only viewports
(setq ss (ssget '((0 . "viewport"))))
(if (IsVpLocked (setq Ename (ssname ss 0)))
;Viewport is locked. Run Unlock commands
(progn
(princ "\nViewport selected is Locked")
;Unlock viewport
(command "_mview" "_Lock" "_OFF" ss "")
;Change viewport color to red to indicate it is Unlocked
(command "_.change" ss "" "_p" "_c" "1" "")
(princ "\nViewport is now Unlocked")
)
;Viewport is unlocked. Run Lock commands
(progn
(princ "\nViewport selected is Unlocked")
;Lock viewport
(command "_mview" "_Lock" "_ON" ss "")
;Change viewport color to ByLayer to indicate it is Locked
(command "_.change" ss "" "_p" "_c" "bylayer" "")
(princ "\nViewport is now Locked")
)
)
(princ)
)
; This function was downloaded from the autodesk discussion groups
; Return: T if locked, Nil otherwise
(defun IsVpLocked (Ename)
(eq 16384 (logand 16384 (cdr (assoc 90 (entget Ename)))))
)
My way:
I have a layer called "viewport", and I switched off the plotoption.
And I use a button macro for locking/unlocking the vp, without changing the color...
Just as You like,
Lothar
ADT 2004
ACAD 2002
RE: Toggle Viewport Disply Lock
Is there an additional advantage to this macro that I'm missing? If so, I may want to add this functionality to the group set-up.
Tks-
C. Fee
RE: Toggle Viewport Disply Lock
I have all of my viewports an layer "viewports" and it set to "no-plot".
I was simply tring to find a quick way to toggle the lock status of a viewport.
I also have a Lisp the will draw a rectangle in model space that is equivelant to the edge of the viewport. I use this so that when I go to edit in model space I know where the edge of the view is.
CODE
;Description: This program will draw a polyline in model space at the extents of the current view port.
; The polyline will be drawn on layer Viewport.
; The user must be inside a viewport when this command is run
;
;Programmer: Kevin Petursson
;Date: July 16, 2003
;Revision: 1.1 - July 17, 2003
;
;
(defun C:port (/ VPctr TMode VP VPsize Currentlayer temp LL UR ctrx ctry LLx LLy URx URy ModelWidth p1 p2 p3 p4)
(setvar "CMDECHO" 0)
(setq VPctr (getvar "VIEWCTR")) ;centrepoint of viewport
(setq TMode (getvar "tilemode"))
(setvar "tilemode" 0)
(setq VP (vports)) ;Get info on the viewports
(setq VPsize (getvar "Viewsize")) ;get the height in model space of the current view port
(setq Currentlayer (getvar "clayer")) ;Get the current layer
;Change the following line to draw the polyline on a different layer
(command "-layer" "make" "viewport" "p" "no" "viewport" "")
(setvar "clayer" "Viewport") ;Set the current layer to Viewport
(setq temp (nth 0 VP))
(setq LL (nth 1 temp))
(setq UR (nth 2 temp))
(setq
ctrx (nth 0 VPctr)
ctry (nth 1 VPctr)
LLx (nth 0 LL)
LLy (nth 1 LL)
URx (nth 0 UR)
URy (nth 1 UR)
ModelWidth (* (- URx LLx) (/ VPsize (- LLy URy)))
)
(setq
p1 (list (- ctrx (/ modelwidth 2)) (- ctry (/ VPsize 2)))
p2 (list (- ctrx (/ modelwidth 2)) (+ ctry (/ VPsize 2)))
p3 (list (+ ctrx (/ modelwidth 2)) (+ ctry (/ VPsize 2)))
p4 (list (+ ctrx (/ modelwidth 2)) (- ctry (/ VPsize 2)))
)
(command "pline" p1 p2 p3 p4 "close")
(setvar "clayer" currentlayer) ;Reset the current layer
(setvar "tilemode" TMode)
(setvar "CMDECHO" 1)
(princ)
)
This one is probably not set for international use either.
RE: Toggle Viewport Disply Lock
ht