chulse Posted December 8, 2009 Posted December 8, 2009 Forgive the lisp newbie here, but how might I call a list of all the viewports in a given layout? Similar to (foreach lay (layoutlist)? And can it be nested in a function like (foreach lay (layoutlist)? Simply put, I'd like a way to lock all the viewports by adding some code to an existing lisp that sets some other variables in each layout. Thanks Quote
ReMark Posted December 8, 2009 Posted December 8, 2009 Lock and unlock viewports with the lisp routine (VPlock_unlock.lsp) submitted by Jason Rhymes in this discussion. http://discussion.autodesk.com/forums/thread.jspa?threadID=468710 Quote
Lee Mac Posted December 8, 2009 Posted December 8, 2009 Well there is: (vports) Which will give you a list of the Viewports by their identification numbers, but this will lock all Viewports: (defun c:lkall (/ i ss ent) (vl-load-com) (if (setq i -1 ss (ssget "_X" '((0 . "VIEWPORT")))) (while (setq ent (ssname ss (setq i (1+ i)))) (vla-put-displaylocked (vlax-ename->vla-object ent) :vlax-true))) (princ)) Lee Quote
chulse Posted December 9, 2009 Author Posted December 9, 2009 So could this work? (foreach vp (vports) (vla-put-displaylocked (vlax-ename->vla-object vp) :vlax-true) ) And in it's greater context (the rest of this does work, although it is slow): (defun c:psfix ( / lay ct vp) (vl-load-com) (setq ct (getvar "ctab")) (foreach lay (layoutlist) (command "_LAYOUT" "_Set" lay "PSLTSCALE" 1) (command "_layout" "_Set" lay "_mspace" "ANNOALLVISIBLE" 1 "_pspace") ) (foreach vp (vports) (vla-put-displaylocked (vlax-ename->vla-object vp) :vlax-true) ) (setvar "msltscale" 1) (setvar "ltscale" 1) (setvar "ctab" ct) );defun Quote
Lee Mac Posted December 9, 2009 Posted December 9, 2009 No, as the (vports) returns a list of viewport identification numbers - the code in the second part of my post will lock all the Viewports Quote
Lee Mac Posted December 9, 2009 Posted December 9, 2009 Try this.. A quick modification of your code: (defun c:psfix ( / ct lay i ss ent) (vl-load-com) (setq ct (getvar "ctab")) (foreach lay (layoutlist) (mapcar 'setvar '("CTAB" "PSLTSCALE") (list lay 1)) (vl-cmdf "_.mspace") (setvar "ANNOALLVISIBLE" 1) (vl-cmdf "_.pspace")) (if (setq i -1 ss (ssget "_X" '((0 . "VIEWPORT")))) (while (setq ent (ssname ss (setq i (1+ i)))) (vl-catch-all-apply 'vla-put-displaylocked (list (vlax-ename->vla-object ent) :vlax-true)))) (mapcar 'setvar '("MSLTSCALE" "LTSCALE" "CTAB") (list 1 1 ct)) (princ)) Quote
chulse Posted December 9, 2009 Author Posted December 9, 2009 Cool, thanks. I was trying to stick with what (little) I was familiar with... I expect your version will be faster too. Quote
chulse Posted December 9, 2009 Author Posted December 9, 2009 Probably dumb of me, but could you comment that a bit to help me understand what you have it doing - I'm not familiar with all those methods? Thanks Lee Quote
chulse Posted December 9, 2009 Author Posted December 9, 2009 Lock and unlock viewports with the lisp routine (VPlock_unlock.lsp) submitted by Jason Rhymes in this discussion. http://discussion.autodesk.com/forums/thread.jspa?threadID=468710 Nice find. Thanks Mark Quote
Lee Mac Posted December 9, 2009 Posted December 9, 2009 Not a problem Cary - I would much rather that you understood what my code was doing rather than just accepting it. If you are still puzzled about anything, just ask. [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:psfix [b][color=RED]([/color][/b] [b][color=BLUE]/[/color][/b] ct lay i ss ent[b][color=RED])[/color][/b] [i][color=#990099];; Initiate Defun and localise Vars[/color][/i] [b][color=RED]([/color][/b][b][color=BLUE]vl-load-com[/color][/b][b][color=RED])[/color][/b] [i][color=#990099];; Load Visual LISP Console[/color][/i] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] ct [b][color=RED]([/color][/b][b][color=BLUE]getvar[/color][/b] [b][color=#ff00ff]"ctab"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [i][color=#990099];; Store Current Layout[/color][/i] [b][color=RED]([/color][/b][b][color=BLUE]foreach[/color][/b] lay [b][color=RED]([/color][/b][b][color=BLUE]layoutlist[/color][/b][b][color=RED])[/color][/b] [i][color=#990099];; For Every Layout in the Drawing[/color][/i] [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]setvar[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b][b][color=#ff00ff]"CTAB"[/color][/b] [b][color=#ff00ff]"PSLTSCALE"[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]list[/color][/b] lay [b][color=#009900]1[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [i][color=#990099];; Apply the function 'setvar' to each argument in each list.[/color][/i] [i][color=#990099];; Setvar needs two arguments, sys var and value, so mapcar needs[/color][/i] [i][color=#990099];; two lists.[/color][/i] [i][color=#990099];; This is equivalent to putting (setvar "CTAB" lay) (setvar "PSLTSCALE" 1)[/color][/i] [b][color=RED]([/color][/b][b][color=BLUE]vl-cmdf[/color][/b] [b][color=#ff00ff]"_.mspace"[/color][/b][b][color=RED])[/color][/b] [i][color=#990099];; Equivalent to (command "_.mspace")[/color][/i] [b][color=RED]([/color][/b][b][color=BLUE]setvar[/color][/b] [b][color=#ff00ff]"ANNOALLVISIBLE"[/color][/b] [b][color=#009900]1[/color][/b][b][color=RED])[/color][/b] [i][color=#990099];; Set Sys Var ANNOALLVISIBLE to 1[/color][/i] [b][color=RED]([/color][/b][b][color=BLUE]vl-cmdf[/color][/b] [b][color=#ff00ff]"_.pspace"[/color][/b][b][color=RED])[/color][/b] [i][color=#990099];; Equivalent to (command "_.pspace")[/color][/i] [b][color=RED])[/color][/b] [i][color=#990099]; end foreach[/color][/i] [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] i [b][color=#009900]-1[/color][/b] ss [b][color=RED]([/color][/b][b][color=BLUE]ssget[/color][/b] [b][color=#ff00ff]"_X"[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b][b][color=RED]([/color][/b][b][color=#009900]0[/color][/b] . [b][color=#ff00ff]"VIEWPORT"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [i][color=#990099];; If there are Viewports in the Database[/color][/i] [b][color=RED]([/color][/b][b][color=BLUE]while[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] ent [b][color=RED]([/color][/b][b][color=BLUE]ssname[/color][/b] ss [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] i [b][color=RED]([/color][/b][b][color=BLUE]1+[/color][/b] i[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [i][color=#990099];; While we can get an entity name in the Selection Set[/color][/i] [b][color=RED]([/color][/b][b][color=BLUE]vl-catch-all-apply[/color][/b] [i][color=#990099];; Apply the following function and catch any errors[/color][/i] [i][color=#990099];; This is like using 'apply' except the program will not crash if[/color][/i] [i][color=#990099];; there is an error executing the function.[/color][/i] [b][color=DARKRED]'[/color][/b][b][color=BLUE]vla-put-displaylocked[/color][/b] [i][color=#990099];; Property of the Viewport to determine if it is locked.[/color][/i] [i][color=#990099];; List of arguments that belong to 'vla-put-displaylocked'[/color][/i] [b][color=RED]([/color][/b][b][color=BLUE]list[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vlax-ename->vla-object[/color][/b] ent[b][color=RED])[/color][/b] [i][color=#990099];; convert the ename to a VLA-object[/color][/i] [b][color=Blue]:vlax-true[/color][color=RED])[/color][/b] [i][color=#990099];; Boolean True - hence the Viewport will be locked[/color][/i] [b][color=RED])[/color][/b] [i][color=#990099]; end vl-catch-all-apply[/color][/i] [b][color=RED])[/color][/b] [i][color=#990099]; end While[/color][/i] [b][color=RED])[/color][/b] [i][color=#990099]; end IF[/color][/i] [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]setvar[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b][b][color=#ff00ff]"MSLTSCALE"[/color][/b] [b][color=#ff00ff]"LTSCALE"[/color][/b] [b][color=#ff00ff]"CTAB"[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]list[/color][/b] [b][color=#009900]1[/color][/b] [b][color=#009900]1[/color][/b] ct[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [i][color=#990099];; Same logic as above - read about 'mapcar' to learn more.[/color][/i] [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b] [i][color=#990099];; Exit Quietly - i.e. suppress last return[/color][/i] [b][color=RED])[/color][/b] [i][color=#990099];; End Defun[/color][/i] Lee PS> Perhaps also look up a few of the functions you are unfamiliar with in the Visual LISP Editor help files -- (VLIDE at command line). Quote
chulse Posted December 9, 2009 Author Posted December 9, 2009 Awesome, thanks I really do need to try the Visual LISP editor. I use Notepad++ for most of my simple work (bats, .lins, etc) Quote
Lee Mac Posted December 9, 2009 Posted December 9, 2009 You're welcome Even if you don't like the editor itself - the help files are indispensable... Quote
chulse Posted January 4, 2010 Author Posted January 4, 2010 Lee, What is the advantage of using: vl-cmdf vs. command ? Quote
Lee Mac Posted January 4, 2010 Posted January 4, 2010 vl-cmdf evaluates the validity of the arguments before proceeding - command doesn't. Quote
chulse Posted January 4, 2010 Author Posted January 4, 2010 Do you know of a good reference for vl, vla, vlax functions and how to use them? Quote
alanjt Posted January 4, 2010 Posted January 4, 2010 Just a minor alteration to Lee's routine... (defun c:psfix ( / #Doc ct lay i ss ent) ;; Initiate Defun and localise Vars (vl-load-com) ;; Load Visual LISP Console (setq ct (getvar "ctab")) ;; Store Current Layout (setq #Doc (vla-get-activedocument (vlax-get-acad-object))) (foreach lay (layoutlist) ;; For Every Layout in the Drawing (mapcar 'setvar '("CTAB" "PSLTSCALE") (list lay 1)) ;; Apply the function 'setvar' to each argument in each list. ;; Setvar needs two arguments, sys var and value, so mapcar needs ;; two lists. ;; This is equivalent to putting (setvar "CTAB" lay) (setvar "PSLTSCALE" 1) [color=Red] ;(vl-cmdf "_.mspace") ;; Equivalent to (command "_.mspace") (and (zerop (getvar 'tilemode)) (vla-put-mspace #Doc :vlax-true))[/color] (setvar "ANNOALLVISIBLE" 1) ;; Set Sys Var ANNOALLVISIBLE to 1 [color=Red] ;(vl-cmdf "_.pspace") ;; Equivalent to (command "_.pspace") (and (zerop (getvar 'tilemode)) (vla-put-mspace #Doc :vlax-false))[/color] ) ; end foreach (if (setq i -1 ss (ssget "_X" '((0 . "VIEWPORT")))) ;; If there are Viewports in the Database (while (setq ent (ssname ss (setq i (1+ i)))) ;; While we can get an entity name in the Selection Set (vl-catch-all-apply ;; Apply the following function and catch any errors ;; This is like using 'apply' except the program will not crash if ;; there is an error executing the function. 'vla-put-displaylocked ;; Property of the Viewport to determine if it is locked. ;; List of arguments that belong to 'vla-put-displaylocked' (list (vlax-ename->vla-object ent) ;; convert the ename to a VLA-object :vlax-true) ;; Boolean True - hence the Viewport will be locked ) ; end vl-catch-all-apply ) ; end While ) ; end IF (mapcar 'setvar '("MSLTSCALE" "LTSCALE" "CTAB") (list 1 1 ct)) ;; Same logic as above - read about 'mapcar' to learn more. (princ) ;; Exit Quietly - i.e. suppress last return ) ;; End Defun Quote
Lee Mac Posted January 4, 2010 Posted January 4, 2010 Do you know of a good reference for vl, vla, vlax functions and how to use them? Yes, the Visual LISP Editor help files Just a minor alteration to Lee's routine... Cheers Alan, I'll note that for next time Quote
alanjt Posted January 5, 2010 Posted January 5, 2010 Yes, the Visual LISP Editor help files Cheers Alan, I'll note that for next time No problem. It was just in case you were unaware. Quote
chulse Posted January 5, 2010 Author Posted January 5, 2010 Awesome, thanks guys. I WILL learn this stuff if it kills me... Quote
CAB Posted January 6, 2010 Posted January 6, 2010 My collection: http://www.theswamp.org/index.php?topic=7097.0 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.