(defun Create_Viewport (/ p1 p2 oldlayer ent)
;; Check if the user is in Paper Space
(if (= (getvar "TILEMODE") 1)
(progn
(alert "This command only works in a Layout (Paper Space).")
(exit)
)
)
;; Ensure we aren't "inside" an existing viewport (Model Space through a VP)
(if (> (getvar "CVPORT") 1)
(command "pspace")
)
;; Setup Layer "Viewl"
(setq oldlayer (getvar "CLAYER"))
(if (not (tblsearch "LAYER" "Mview"))
(command
"-LAYER"
"M" "Mview"
"C" "2" ""
"LW" "0.05" "Mview"
"P" "N" "Mview" ""
""
)
) ; "m" (Make) creates if missing and sets current
;; Make sure the Mview layer is set to NOPLOT
(command "-layer" "p" "n" "Mview" "")
;; Prompt user for Viewport points
(setq p1 (getpoint "\nSpecify first corner of viewport: "))
(setq p2 (getcorner p1 "\nSpecify opposite corner: "))
(if (and p1 p2)
(progn
;; Create the Viewport
(command "mview" p1 p2)
;; Set "Legacy Hidden" for the last created object (the viewport)
(setq ent (entlast))
(command "mview" "s" "h" ent "") ; Shadeplot -> Hidden
;; Ensure it's on the "Mview" layer (even if the user changed layers manually)
(command "chprop" ent "" "la" "Mview" "")
(princ "\nViewport created on layer 'Mview' with Legacy Hidden shadeplot.")
)
(princ "\nViewport creation cancelled.")
)
(princ)
)