Author Topic: Viewport Toggle Lock (revisited)  (Read 2642 times)

0 Members and 1 Guest are viewing this topic.

pmvliet

  • Guest
Viewport Toggle Lock (revisited)
« on: May 25, 2005, 05:59:36 PM »
Browsing this topic I found the following code from Daron and Seven

http://www.theswamp.org/phpBB2/viewtopic.php?t=631

I really like it and have tweaked it some to fit our company standards, but I have one question/problem. The following command/function does not work

Code: [Select]
(defun c:tva () (command "togglevplock" "all")(princ))
"togglevplock" works at the command prompt, but not defined as TVA.
Seems like something silly...

How hard would it be to not have this be a toggle and either set all the viewports locked or un-locked? I will be pondering on this..

Thanks,
Pieter

ronjonp

  • Needs a day job
  • Posts: 7529
Viewport Toggle Lock (revisited)
« Reply #1 on: May 25, 2005, 06:20:08 PM »
I modified this one that CAB posted:

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

  (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...")
      )
      ((= X "Unlock")
       (setq lck :vlax-false
             prmpt "unlocked...")
      )
)
  (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")
         (vla-put-displaylocked ent lck)
        )
      )
    )
  )
(princ (strcat "\n All viewports have been " prmpt))
(princ)
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Viewport Toggle Lock (revisited)
« Reply #2 on: May 25, 2005, 07:36:46 PM »
Here's one I put together a while back. It has the advantage of not looping through each of the paperspace blocks.
Code: [Select]

(defun vplock (yesno / ss lock x obj)
  (if (setq ss (ssget "X" '((0 . "VIEWPORT")(-4 . "/=")(69 . 1))))
    (progn
      (if (= "y" yesno) (setq lock :vlax-true)(setq lock :vlax-false))
      (setq x 0)
      (while (< x (sslength ss))
(setq obj (vlax-ename->vla-object (ssname ss x)))
(vla-put-displaylocked obj lock)
(setq x (1+ x))
)
      )
    (princ "\nNo paperspace viewports found....")
    )
  (princ)
  )

Then create commands for Lock or Unlock like so:
Code: [Select]

(defun c:lockall () (vplock "y")(princ))
(defun c:unlockall () (vplock "n")(princ))

delium55

  • Guest
Lock and unlock viewport
« Reply #3 on: May 26, 2005, 12:51:09 AM »
Here some macros  of my custom menu.

[->Fenêtre]
ID_Vport_lockon     [Affichage verrouillé]^C^C_-vports _lock _on _p;;
ID_Vport_lockoff     [<-Affichage libéré]^C^C_-vports _lock _off _p;;
        [Verrouille toutes fenêtres]^C^C-LA;T;VPORT;;-vport;l;on;all;;
        [Libère toutes fenêtres]^C^C-LA;T;VPORT;;-vport;l;off;all;;


Françcois

CADaver

  • Guest
Re: Viewport Toggle Lock (revisited)
« Reply #4 on: May 26, 2005, 09:26:17 AM »
Quote from: pmvliet
"togglevplock" works at the command prompt, but not defined as TVA.
Can't answer your "real" question, but just FYI. "TOGGLEVPLOCK" is a lisp function, not a command.  So it won't run from
Code: [Select]
(command "togglevplock" ....)  It amy work if called as a routine by
Code: [Select]
(defun c:tva () (togglevplock)) but not knowing anything about the code, I'm just guessing.

daron

  • Guest
Viewport Toggle Lock (revisited)
« Reply #5 on: May 26, 2005, 10:52:18 AM »
Oops. I think you'd be right. You could check and see if tvl works. If so, emulate that in the tva portion as Cadaver has already pointed out.

pmvliet

  • Guest
Viewport Toggle Lock (revisited)
« Reply #6 on: May 26, 2005, 03:04:35 PM »
Thanks!
I will look through all of this in the next day. I really like Daron and Seven's program even if it is a little complex for my lisping abilities  :D

Pieter

daron

  • Guest
Viewport Toggle Lock (revisited)
« Reply #7 on: May 26, 2005, 03:30:44 PM »
I like it too. Use it all the time. Thanks.