TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: TJAM51 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
-
Hi
Have a browse of the following thread...
Viewport Toggle Lock (revisited) (http://www.theswamp.org/phpBB2/viewtopic.php?t=5330)
Have a good one, Mike
-
This is what I use:
; 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
-
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.
-
Yes, I see. Sorry. Good work on yours!
Gotta look before I leap, I think. You all are just to quick for me! :)
-
Yep..
;; 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)
)
-
Daron, there is no way you can prove that I had a hand in that progy. ...It was all you baby!
-
I looked but couldn't find the old thread.
I did have these in my folder.
http://theswamp.org/lilly_pond/cab/vp%20lock%20by%207%20new.LSP?nossi=1
http://theswamp.org/lilly_pond/cab/VP%20Lock%20by%207.lsp?nossi=1
-
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.
-
You could also add it to a menu like this
[Lock VP]^C^C_mview;lock;on;all;;
[UnLock VP]^C^C_mview;lock;off;all;;
-
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.
-
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
(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)
)
-
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.
;; 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)
)
-
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.
-
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.
-
Yeh thats true I had to manually lock each vport.It got me by but these new solutions are great.
-
OK Ron,
Here is my study on viewport locking.
http://www.theswamp.org/forum/index.php?topic=7097.new#new
-
CAB,
How did you find the 340 code?
-
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-)
-
Thanks.