matthewrussell Posted December 10, 2008 Share Posted December 10, 2008 Hey people, I have been having trouble making a lisp routine that will draw a viewport on a set layer and then once thats done will automatically go back to the previous layer that i had selected. I couldnt get it to work so I came here. This is what i had ;Draw Viewport In Viewport Layer (defun c:mvp (setq layerset (getvar "clayer")) (setvar "clayer" "0-VPort") (command "mview") (setvar "clayer" layerset) (princ) ) ;defun Cheers Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 10, 2008 Share Posted December 10, 2008 This is a LISP that I made for another guy on here, it may help you with yours: (defun c:vp (/ oldlay) (setq oldlay (getvar "clayer")) (setvar "cmdecho" 0) (if (/= (getvar "ctab") "Model") (progn (if (not (tblsearch "LAYER" "vport")) (command "-layer" "M" "vport" "C" "49" "vport" "P" "N" "vport" "") (setvar "clayer" "vport") ) ; end if (command "-vports" pause pause ) ; end command (setvar "clayer" oldlay) ) ; end progn (alert "Viewport Cannot be Drawn in Model Space.") ) ; end if (setvar "cmdecho" 1) (princ) ) ; end defun Quote Link to comment Share on other sites More sharing options...
matthewrussell Posted December 10, 2008 Author Share Posted December 10, 2008 Cheers for that Lee. I changed a few little things in it to suit our drafting standards but it works like a charm. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 11, 2008 Share Posted December 11, 2008 No probs Matt, happy to help Quote Link to comment Share on other sites More sharing options...
au-s Posted January 19, 2009 Share Posted January 19, 2009 Hey, That is great ... thanx! Allthough I wanted to combine your lisp with inserting an Xref with layer Xref after the Vport had been made. When I do it it pauses after making vport, the program enters mspace and then: Command: Invalid option keyword. BUT try to run this once, and when the layers are made, XREF and VPORT, the next time you run the lisp it works ... what is wrong? And thats is .. Here is the code..: (defun c:AIX:XREFINRITDEF (/ oldlay) (setq oldlay (getvar "clayer")) (setvar "cmdecho" 0) (if (/= (getvar "ctab") "Model") (progn (if (not (tblsearch "LAYER" "vport")) (command "._layer" "M" "vport" "C" "7" "vport" "P" "N" "vport" "") (setvar "clayer" "vport") ) ; end if (prompt "Skapar ett nytt Mview-Fönster...") (command "-vports" pause pause ) ; end command (setvar "clayer" oldlay) ) ; end progn (alert "Mview-fönsret Kan Ej skapas i Modellen!!") ) ; end if (setvar "cmdecho" 1) ;;;INSERT XREF (command "._mspace") (command "_.ucs" "w") (setq oldlay (getvar "clayer")) (setvar "cmdecho" 0) (if (tblsearch "layer" "XREF") (command "_layer" "s" "XREF" "") (command "_layer" "m" "XREF" "c" "7" "" "d" "ExternReferens" "XREF" "lo" "XREF" "" ) ) (command "._XAttach") (while (> (getvar "CMDACTIVE") 0) (command pause) ) (setvar "clayer" oldlay) (setvar "cmdecho" 1) (command "_.ucs" "p") (command "._pspace") (princ) ) ; end defun Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 19, 2009 Share Posted January 19, 2009 You encounter a problem when trying to delete a layer (i assume that is what you are trying to do.) this cannot be done via the "-layer" command. I have tidied the code up a bit also - this should work (although untested!): (defun c:AIX:XREFINRITDEF (/ varlist oldvars) (setq varlist (list "CMDECHO" "CLAYER" "CTAB") oldvars (mapcar 'getvar varlist)) (setvar "cmdecho" 0) (if (/= (getvar "ctab") "Model") (progn (if (not (tblsearch "LAYER" "vport")) (command "-layer" "M" "vport" "C" "7" "vport" "P" "N" "vport" "") (setvar "clayer" "vport")) (prompt "Skapar ett nytt Mview-Fönster...") (command "-vports" pause pause)) (alert "Mview-fönsret Kan Ej skapas i Modellen!!")) ;;;INSERT XREF (setvar "ctab" "MODEL") (command "_.ucs" "w") (if (not (tblsearch "LAYER" "XREF")) (command "-layer" "M" "XREF" "C" "7" "XREF" "LO" "XREF" "") (setvar "clayer" "XREF")) (command "._XAttach") (while (> (getvar "CMDACTIVE") 0) (command pause)) (command "_.ucs" "P") (mapcar 'setvar varlist oldvars) (princ)) Quote Link to comment Share on other sites More sharing options...
au-s Posted January 20, 2009 Share Posted January 20, 2009 Great!!! It works fine. Thank you very much Sir. Is it possible to develop this lisp a little bit to make a statement to choose to create vport or not? Sometimes it happens that you already have vports set so you do not need to create ones. So I want to make a user to choose from to create vport or not to. Like that: (setq answer (dos_msgbox "New VPORT..."Do you want to create New VPORT?..." 4 3)) (if answer ( = 6) (command "-vports" pause pause))) ) I tried to place it in a good spot but couldnt manage and the lisp just inserts an xref and skipping this dos_msg box... Thanx for help! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 20, 2009 Share Posted January 20, 2009 I've never used a "dos_msgbox", but this should accomplish the same thing: (defun c:AIX:XREFINRITDEF (/ varlist oldvars ans) (setq varlist (list "CMDECHO" "CLAYER" "CTAB") oldvars (mapcar 'getvar varlist)) (setvar "cmdecho" 0) (initget "Yes No") (setq ans (getkword "\nCreate a Viewport? [Yes/No] <Yes> : ")) (if (/= ans "No") (progn (if (/= (getvar "ctab") "Model") (progn (if (not (tblsearch "LAYER" "vport")) (command "-layer" "M" "vport" "C" "7" "vport" "P" "N" "vport" "") (setvar "clayer" "vport")) (prompt "Skapar ett nytt Mview-Fönster...") (command "-vports" pause pause)) (alert "Mview-fönsret Kan Ej skapas i Modellen!!")))) ;;;INSERT XREF (setvar "ctab" "MODEL") (command "_.ucs" "w") (if (not (tblsearch "LAYER" "XREF")) (command "-layer" "M" "XREF" "C" "7" "XREF" "LO" "XREF" "") (setvar "clayer" "XREF")) (command "._XAttach") (while (> (getvar "CMDACTIVE") 0) (command pause)) (command "_.ucs" "P") (mapcar 'setvar varlist oldvars) (princ)) Quote Link to comment Share on other sites More sharing options...
au-s Posted January 20, 2009 Share Posted January 20, 2009 Thanx Sir! It exactly does the thing I wanted... There is only one prob ... If I use the lisp in model.dwg it do not cancel the whole script which it did before. If I am in a model-drawing it should cancel the whole thing .. Sorry I harass you but it got lost on the way Many thanx!! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 20, 2009 Share Posted January 20, 2009 Would you like it to cancel the XREF when you are in model space? Only reason I ask is that the LISP is programmed to switch to model space in order to insert the XREF anyway - so it wouldn't matter whether or not the user is in model space to start with. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 20, 2009 Share Posted January 20, 2009 If that indeed is what you are after: (defun c:AIX:XREFINRITDEF (/ varlist oldvars ans) (setq varlist (list "CMDECHO" "CLAYER" "CTAB") oldvars (mapcar 'getvar varlist)) (setvar "cmdecho" 0) (if (/= (getvar "ctab") "Model") (progn (initget "Yes No") (setq ans (getkword "\nCreate a Viewport? [Yes/No] <Yes> : ")) (if (/= ans "No") (progn (if (not (tblsearch "LAYER" "vport")) (command "-layer" "M" "vport" "C" "7" "vport" "P" "N" "vport" "") (setvar "clayer" "vport")) (prompt "Skapar ett nytt Mview-Fönster...") (command "-vports" pause pause))) (setvar "ctab" "MODEL") (command "_.ucs" "w") (if (not (tblsearch "LAYER" "XREF")) (command "-layer" "M" "XREF" "C" "7" "XREF" "LO" "XREF" "") (setvar "clayer" "XREF")) (command "._XAttach") (while (> (getvar "CMDACTIVE") 0) (command pause)) (command "_.ucs" "P")) (alert "Mview-fönsret Kan Ej skapas i Modellen!!")) (mapcar 'setvar varlist oldvars) (princ)) Quote Link to comment Share on other sites More sharing options...
au-s Posted January 20, 2009 Share Posted January 20, 2009 Would you like it to cancel the XREF when you are in model space? Only reason I ask is that the LISP is programmed to switch to model space in order to insert the XREF anyway - so it wouldn't matter whether or not the user is in model space to start with. Exactly! That works fine when I am in a Layout.dwg-drawing!! But when I am in model-drawing.dwg it does: 1. I call the command 2. It tells me (alert "Mview-fönsret Kan Ej skapas i Modellen!!")) which means "VPORT-window cannot be created in model-drawing.dwg". The lisp works fine in Layout-drawing but it should terminate after the alert "Viewport Cannot be Drawn in Model Space" as you did the first time when I am in model-drawing.dwg. That is why I find it very useful. I have two lisps. One that insert xrefs in modelspace and one in layout-drawing.dwg. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 20, 2009 Share Posted January 20, 2009 In the LISP posted above - the XREF will only be inserted if you are initially in Layout Space. Although, please note that the XREF is being inserted into model space, and the value of "ctab" is being re-instated at the end of the LISP. (to switch back to layout-space.) Quote Link to comment Share on other sites More sharing options...
au-s Posted January 20, 2009 Share Posted January 20, 2009 In the LISP posted above - the XREF will only be inserted if you are initially in Layout Space. Although, please note that the XREF is being inserted into model space, and the value of "ctab" is being re-instated at the end of the LISP. (to switch back to layout-space.) Hehe... take a look at this code ... (defun C:AIX:XREFINRITDEF (/ varlist oldvars ans) (setq varlist (list "CMDECHO" "CLAYER" "CTAB") oldvars (mapcar 'getvar varlist)) (setvar "cmdecho" 0) (initget "Yes No") (setq ans (getkword "\nSkapa ett Nytt VPORT?? [JA/Nej] <JA> : ")) (if (/= ans "Nej") (progn (if (/= (getvar "ctab") "Model") (progn (if (not (tblsearch "LAYER" "vport")) (command "-layer" "M" "vport" "C" "7" "vport" "P" "N" "vport" "") (setvar "clayer" "vport")) (prompt "Skapar ett nytt Mview-Fönster...") (command "-vports" pause pause)) (alert "Mview-fönsret Kan Ej skapas i Modellen!!")))) ;;;INSERT XREF (command "_mspace") (command "_.ucs" "w") (if (not (tblsearch "LAYER" "XREF")) (command "-layer" "M" "XREF" "C" "7" "XREF" "LO" "XREF" "") (setvar "clayer" "XREF")) (command "._XAttach") (while (> (getvar "CMDACTIVE") 0) (command pause)) (command "_.ucs" "P") (command "_pspace") (mapcar 'setvar varlist oldvars) (princ) );;; END DEFUN When in modelTAB the lisp executes anyways even after alert. I changed while in layouTAB to : (command "_mspace") then after commands beeing done and xrefs chosen (command "_pspace") ... So, problem is that the script contiunes when Im in modelTAB which it shouldnt. It should only work in LayoutTAB. Thanx Sir! I hope Im not to much trouble Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 20, 2009 Share Posted January 20, 2009 My LISP in post #11 will not operate in Model Space. I have just tested it to be sure. Quote Link to comment Share on other sites More sharing options...
au-s Posted January 20, 2009 Share Posted January 20, 2009 THANX!! All work now Here is with the dos_msgbox and DosLib... I think its better Thank you for helping me out... Truly apprciate it!! defun c:AIX:XREFINRITDEF (/ varlist oldvars ans) (setq varlist (list "CMDECHO" "CLAYER" "CTAB") oldvars (mapcar 'getvar varlist)) (setvar "cmdecho" 0) (if (/= (getvar "ctab") "Model") (progn (setq svar (dos_msgbox "Create VPORT?" "New Window" 4 3 ) ) (IF (= svar 6) (progn (if (not (tblsearch "LAYER" "vport")) (command "-layer" "M" "vport" "C" "7" "vport" "P" "N" "vport" "") (setvar "clayer" "vport")) (prompt "Skapar ett nytt Mview-Fönster...") (command "-vports" pause pause))) (setvar "ctab" "MODEL") (command "_.ucs" "w") (if (not (tblsearch "LAYER" "XREF")) (command "-layer" "M" "XREF" "C" "7" "XREF" "LO" "XREF" "") (setvar "clayer" "XREF")) (command "._XAttach") (while (> (getvar "CMDACTIVE") 0) (command pause)) (command "_.ucs" "P")) (alert "VPORT cant be created in modelspace.!!")) (mapcar 'setvar varlist oldvars) (princ)) Thanx SIR!! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 20, 2009 Share Posted January 20, 2009 No Probs - happy to help Although I do have one question however: How do you make the dos_msgbox work? Obviously it is not a recognised LISP function, so how does it operate? Quote Link to comment Share on other sites More sharing options...
David Bethel Posted January 20, 2009 Share Posted January 20, 2009 Lee, My guess is that it is part of DOSLIB http://www.en.na.mcneel.com/doslib.htm A really good tool, but don't assume that everyone has it installed. -David Quote Link to comment Share on other sites More sharing options...
au-s Posted January 20, 2009 Share Posted January 20, 2009 Lee, My guess is that it is part of DOSLIB http://www.en.na.mcneel.com/doslib.htm A really good tool, but don't assume that everyone has it installed. -David Exactly!! You need to download DOSlib and have it in your system. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 20, 2009 Share Posted January 20, 2009 Thanks for the link David, am downloading it now Quote Link to comment Share on other sites More sharing options...
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.