Author Topic: Viewport locking  (Read 5891 times)

0 Members and 1 Guest are viewing this topic.

TJAM51

  • Guest
Viewport locking
« on: July 22, 2005, 07:41:57 AM »
Is there anyway to run the command to lock viewports in a script or lisp routine? I would like to run the routine without having to pick the viewports.


Thanks

MikePerry

  • Guest
Viewport locking
« Reply #1 on: July 22, 2005, 08:39:32 AM »
Hi

Have a browse of the following thread...

Viewport Toggle Lock (revisited)

Have a good one, Mike

Birdy

  • Guest
Viewport locking
« Reply #2 on: July 22, 2005, 08:43:40 AM »
This is what I use:
Code: [Select]
; Written By: Peter Jamtgaard 2002
; This function will display lock all viewports in a drawing.

(defun C:LOCKVP (/ CNT EOBJ SSET)
 (vl-load-com)
 (setq SSET (ssget "x" (list (cons 0 "VIEWPORT")))
       CNT  0
 )
 (repeat (sslength SSET)
  (setq EOBJ (vlax-ename->vla-object (ssname SSET CNT))
        CNT  (1+ CNT)
  )
  (vla-put-DisplayLocked EOBJ :vlax-true)
 )
 (prin1)
)

; MODIFIED  2005
; This function will UNLOCK all viewports in a drawing.

(defun C:UNLOCKVP (/ CNT EOBJ SSET)
 (vl-load-com)
 (setq SSET (ssget "x" (list (cons 0 "VIEWPORT")))
       CNT  0
 )
 (repeat (sslength SSET)
  (setq EOBJ (vlax-ename->vla-object (ssname SSET CNT))
        CNT  (1+ CNT)
  )
  (vla-put-DisplayLocked EOBJ :vlax-FALSE)
 )
 (prin1)
)

I saw a similar one (here I think, by CAB?)
that toggles viewport lock / unlock and changes the color (red/ green) depending on the state. Pretty nice.

edit: ok, I'm a little slow... :D

daron

  • Guest
Viewport locking
« Reply #3 on: July 22, 2005, 08:46:31 AM »
Birdy, while CAB has done lots of great work, the one you refer to by him? is the one Mike referred TJam to written by Se7en and myself.

Birdy

  • Guest
Viewport locking
« Reply #4 on: July 22, 2005, 08:49:25 AM »
Yes, I see. Sorry. Good work on yours!
Gotta look before I leap, I think.  You all are just to quick for me! :)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Viewport locking
« Reply #5 on: July 22, 2005, 08:57:00 AM »
Yep..
Code: [Select]
;; unlock all vp & set color to green  06/07/04
(defun c:vpunlockall ()
  (vl-load-com)
  (vlax-for lay
                (vla-get-layouts
                  (vla-get-activedocument
                    (vlax-get-acad-object)
                  )
                )
    (if (eq :vlax-false (vla-get-modeltype lay))
      (vlax-for ent (vla-get-block lay) ; for each ent in layout
        (if (= (vla-get-objectname ent) "AcDbViewport")
          (progn
            (vla-put-displaylocked ent :vlax-false)
            (vla-put-color ent 3); 3 green
          )
        )
      )
    )
  )
  (prompt "\n***  All viewports are UnLocked  ***")
  (princ)
)

;;  lock all vp and set color to red  06/07/04
(defun c:vplockall ()
  (vl-load-com)
  (vlax-for lay
                (vla-get-layouts
                  (vla-get-activedocument
                    (vlax-get-acad-object)
                  )
                )
    (if (eq :vlax-false (vla-get-modeltype lay))
      (vlax-for ent (vla-get-block lay) ; for each ent in layout
        (if (= (vla-get-objectname ent) "AcDbViewport")
          (progn
            (vla-put-displaylocked ent :vlax-true)
            (vla-put-color ent 1);1 red
          )
        )
      )
    )
  )
  (prompt "\n***  All viewports are Locked  ***")
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

JohnK

  • Administrator
  • Seagull
  • Posts: 10652
Viewport locking
« Reply #6 on: July 22, 2005, 09:54:06 AM »
Daron, there is no way you can prove that I had a hand in that progy. ...It was all you baby!
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Viewport locking
« Reply #7 on: July 22, 2005, 10:10:23 AM »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

daron

  • Guest
Viewport locking
« Reply #8 on: July 22, 2005, 12:27:57 PM »
John, I would never have figured out Vlisp if you hadn't taught me through the creation of that proggy. Sure it could use a lot of clean up and it has a lot of Mark's code in it, but no matter how much you deny it, you helped build it. Plus, it was built the week of April 4th, 2003.

bman

  • Guest
Viewport locking
« Reply #9 on: July 25, 2005, 01:50:38 PM »
You could also add it to a menu like this
       
Code: [Select]

 [Lock VP]^C^C_mview;lock;on;all;;
 [UnLock VP]^C^C_mview;lock;off;all;;

daron

  • Guest
Viewport locking
« Reply #10 on: July 26, 2005, 07:56:14 AM »
Oh, but that won't lock all vports in all layouts, nor will it let you select any, nor will it change the color of the viewports to give a visual queue to the user of the current state of the vport, nor will it ensure that all viewports are on the same layer, nor wil it ensure that they are on, thawed, unlocked and non-plottable. Have a look at the code bman.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Viewport locking
« Reply #11 on: September 30, 2005, 05:14:58 PM »
Hey CAB (or anyone else for that matter),

How would you check to see if the viewport is a polygon? So far this code I have will lockall but only change the color of rectangular viewports.

;UNLOCK OR LOCK ALL VPORTS

Code: [Select]
(defun c:vplockall ( / X lck prmpt ent clr) 

(vl-load-com)
(initget 0 "Lock Unlock")
(if (not *default*)
  (setq *default* "Lock")
)
(setq X
       (cond
((getkword
    (strcat "\n (L)ock or (U)nlock all viewports?  <<Hit Enter for "
    *default*
    ">>: "
    )
  )
)
(*default*)
       )
)
(setq *default* X)
(cond ((= X "Lock")
       (setq lck :vlax-true
             prmpt "locked..."
             clr 5)
      )
      ((= X "Unlock")
       (setq lck :vlax-false
             prmpt "unlocked..."
             clr 1)
      )
)

(vlax-for lay
      (vla-get-layouts
(vla-get-activedocument
  (vlax-get-acad-object)
)
      )
  (if (eq :vlax-false (vla-get-modeltype lay))
    (vlax-for ent (vla-get-block lay) ; for each ent in layout
      (if (= (vla-get-objectname ent) "AcDbViewport")
(progn
  (vla-put-displaylocked ent lck)
  (vla-put-color ent clr)
)
      )
    )
  )
)
(princ (strcat "\n All viewports have been " prmpt))
(princ)
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Viewport locking
« Reply #12 on: September 30, 2005, 10:39:32 PM »
ron,
There may be a cleaner way to do without switching back to
an entity but I could not find a method to do it.
The problem is I can't find a vla equivalent for the dxf 340 code.

Code: [Select]
;; unlock all vp & set color to green  Revised 09/30/05 - CAB
(defun c:vpunlockall (/ lay obj ent)
  (vl-load-com)
  (vlax-for lay
                (vla-get-layouts
                  (vla-get-activedocument
                    (vlax-get-acad-object)
                  )
                )
    (if (eq :vlax-false (vla-get-modeltype lay))
      (vlax-for obj (vla-get-block lay) ; for each obj in layout
        (if (= (vla-get-objectname obj) "AcDbViewport")
          (progn
            (vla-put-displaylocked obj :vlax-false)
            (vla-put-color obj acGreen)
            (if (setq ent (assoc 340  (entget (vlax-vla-object->ename obj))))
              (vla-put-color (vlax-ename->vla-object (cdr ent)) acGreen)
            )
          )
        )
      )
    )
  )
  (prompt "\n***  All viewports are UnLocked  ***")
  (princ)
)

;;  lock all vp and set color to red  Revised 09/30/05 - CAB
(defun c:vplockall (/ lay obj ent)
  (vl-load-com)
  (vlax-for lay
                (vla-get-layouts
                  (vla-get-activedocument
                    (vlax-get-acad-object)
                  )
                )
    (if (eq :vlax-false (vla-get-modeltype lay))
      (vlax-for obj (vla-get-block lay) ; for each obj in layout
        (if (= (vla-get-objectname obj) "AcDbViewport")
          (progn
            (vla-put-displaylocked obj :vlax-true)
            (vla-put-color obj acRed)
            (if (setq ent (assoc 340  (entget (vlax-vla-object->ename obj))))
              (vla-put-color (vlax-ename->vla-object (cdr ent)) acRed)
            )
          )
        )
      )
    )
  )
  (prompt "\n***  All viewports are Locked  ***")
  (princ)
)

I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

hyposmurf

  • Guest
Re: Viewport locking
« Reply #13 on: October 01, 2005, 05:38:01 AM »
Both those bits of codes are cool.This is what I used to use in my old company as there was just me creating creating drawings.Now Im in a office where most dont keep to standard layer names so my has macro become redundant.
^C^C-LAYER;F;LAYER_NAME;LO;LAYER_NAME;;
The visual queue is that the vports vanish when frozen.Also locks the viewport layer rather than the viewport, but if its frozen you cant select it anyway.
« Last Edit: October 01, 2005, 05:41:45 AM by hyposmurf »

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Viewport locking
« Reply #14 on: October 01, 2005, 10:05:31 AM »
Trouble is, hypo, is that even if a VP's layer is frozen & locked a user can still zoom around inside the VP which screws up any scale. By locking the VP it prevents that.

hyposmurf

  • Guest
Re: Viewport locking
« Reply #15 on: October 01, 2005, 01:29:12 PM »
Yeh thats true I had to manually lock each vport.It got me by but these new solutions are great.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Viewport locking
« Reply #16 on: October 01, 2005, 04:09:02 PM »
OK Ron,
Here is my study on viewport locking.

http://www.theswamp.org/forum/index.php?topic=7097.new#new
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Viewport locking
« Reply #17 on: October 03, 2005, 09:33:14 AM »
CAB,

How did you find the 340 code?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Viewport locking
« Reply #18 on: October 03, 2005, 10:01:28 AM »
Short answer, I don't remember.

Long answer, While working on a routine the did something to a viewport there was a need
to select the viewport & someone testing discovered it would not select an irregular vp.
So the search was on & I found or was given the answer. 340 !
If I found it it was at AutoDesk forum or if someone suggested it I don't remember who.
I found an old link to a previous post but the link was lost during the transition to
the new board. Sorry. 8-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Viewport locking
« Reply #19 on: October 03, 2005, 10:21:55 AM »
Thanks.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC