×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Toggle Viewport Disply Lock

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]

RE: Toggle Viewport Disply Lock

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*" "")
)

RE: Toggle Viewport Disply Lock

(OP)
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.

RE: Toggle Viewport Disply Lock

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

RE: Toggle Viewport Disply Lock

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

RE: Toggle Viewport Disply Lock

(OP)
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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources