Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Toggle Viewport Disply Lock

Status
Not open for further replies.

thalon

Mechanical
Sep 24, 2003
68
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]
 
Hmmm. What I do is to put the viewports or layer Defpoints, then use LF and LT macros below to freeze and thaw. Also, the LU and LL macros to unlock and lock them.

(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*" "")
)
 
It was more the toggle aspect that I was going for. I wanted to be able to quickly flip the lock on a viewport if I need to change it. I added the colour to make it obvious to myself the condition of the viewport.

I appriciate the comments.
 
thalon,

nice lisp, but You can only use it with american/british versions.
International:
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)))))
)

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
 
Please help me understand the utility of this macro. Does it allow you to match the properties of another existing viewport? Or is it designed to alter the "locked-y/n" properties of an individual viewport? Like lothar above, I just put my viewports on a layer "vports" , set the color to 8 ('cause I still want to see it as I'm working) and set the plot-no option for layer vports. Then its a simple matter to click on the viewport, right-click to properties and change the locked/unlocked setting on the fly.

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
 
No. No real advantage. I'm just lazy enough to not want to have to go to the properties menu every time I want to change the "locked-y/n". I also like the LISP as it sets the color of the viewport to indicate that it is Unlocked. The LISP will allow the selection of multiple viewports, and willl set all of the based of the first viewport selected. So is you have 3 viewports, and need to lock them all, it a simple matter to select all three and run the lisp.

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:
;Program Name: port
;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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor