I'm not sure about others, but I see users make mistakes all the time when creating Viewports. They accidentally type in the wrong XP syntax, forget to place the Viewport on the designated viewport layer or forget to lock the viewport once created. Well, I think I've got a nice code that extremely speeds up all this. The Code below will start off by prompting you to create a viewport rectangle. Just select the Bottom Left start point and a Top right corner for the viewport. Then it will prompt you for a scale factor. You can see in the list that 48 is 1/4"- and 96 is 1/8" and so on. You can modify this to any other scale factor you use. Once you choose the scale factor you want it will ask for the center point of your viewport and create you're viewport for you. All on the correct scale, Layer and locked so you can work from floating model space.
Hopefully this code will make things a little easier.
(defun c:makev (/ scale center cl os newscale p1 p2 tm)
(setq tm (getvar "tilemode"))
(setvar "tilemode" 0)
(setq cl (getvar "clayer"))
(setvar "clayer" "defpoints")
(setq os (getvar "osmode"))
(setvar "osmode" 0)
(setq p1 (getpoint "\nSpecify Top Left Point of Viewport: "))
(setq p2 (getcorner p1 "\nSpecify Bottom Right Point of Viewport: "))
(command "mview" p1 p2)
(command "mspace")
(setq scale (strcase (getSTRING "\nSpecify Viewport Scale Factor: 1/2/4/8/12/16/24/32/48/64/96/128 <48>:")))
(setq center (getpoint "\nSpecify Viewport Center Point:"))
(if (= scale "") (setq newscale "1/48xp"))
(if (= scale "1") (setq newscale "1/1xp"))
(if (= scale "2") (setq newscale "1/2xp"))
(if (= scale "4") (setq newscale "1/4xp"))
(if (= scale "8") (setq newscale "1/8xp"))
(if (= scale "12") (setq newscale "1/12xp"))
(if (= scale "16") (setq newscale "1/16xp"))
(if (= scale "24") (setq newscale "1/24xp"))
(if (= scale "32") (setq newscale "1/32xp"))
(if (= scale "48") (setq newscale "1/48xp"))
(if (= scale "64") (setq newscale "1/64xp"))
(if (= scale "96") (setq newscale "1/96xp"))
(if (= scale "128") (setq newscale "1/128xp"))
(command "zoom" "c" center newscale)
(command "-vports" "L" "ON" "ALL" "")
(command "pspace")
(setvar "clayer" cl)
(setvar "osmode" os)
(setvar "tilemode" tm)
(princ))
Click here to download the Lisp file -Download makev.LSP



Make viewport code doesn't
work in my station.
I get this:
makev ; error: no function definition: VARGET
What do I need to do here?
Posted by: Jesus Delgado | July 11, 2005 at 08:42 AM
Very good job!! I missed that little snipet of code. The Variable (VARGET and (VARSET are variable toggles I use in some codes. Of course forgot to get rid of them before I posted the code. Thank you for the heads up!! I updated the post and download. If it still dosent work just send me an e-mail and i'll help you out. Hope it works.
Mark
Posted by: Mark Douglas | July 11, 2005 at 08:39 PM
I would like to adapt viewports for 3D viewing. This would mean that one port would slave to the other in maintaining the lookangle and distance from the target with an offset angle to approximate parallax. Is there such a lisp routine to create something like this? Thanks
Posted by: JPMay | October 27, 2006 at 12:03 PM