@Jonathan3891 ,
Thanks for the dwg. So that would be QUITE a bit above my current skill level. It would require calculating vectors and intersections at planes (maybe irregularly shaped sometimes?) of solids in model space. I can grasp the concept, but the coding aspect of it is out of my reach..
BUT if you're willing to sacrifice hours of coding for 1 extra click, then give this one a go.. It activates the viewport (like you didn't want) but why reinvent what AutoCAD has already given us with our awesome (getpoint) ability?
It will also work if you are in model space or already in a viewport.
(defun c:GZ ( / *error* tm vp cvp startedInVP pt elev)
;Get Z value
;error handle
(defun *error* (msg)
(if (and (= 0 tm) (not startedInVP)) (command-s "_.PSPACE"))
(if (not (member msg '("Function cancelled" "quit / exit abort")))
(princ (strcat "\nError: " msg))
);if
(princ)
);defun
;prep conditions
(cond
((and (= 1 (getvar 'CVPORT)) (= 0 (setq tm (getvar 'TILEMODE))))
(while (not (progn (prompt "\nSelect ViewPort: ") (setq vp (ssget "_+.:E:S" '((0 . "VIEWPORT"))))))
(prompt "...Invalid.")
);while
(setq vp (ssname vp 0) cvp (cdr (assoc 69 (entget vp))))
(command "_.MSPACE") (setvar 'CVPORT cvp)
);cond 1
((= 0 tm)
(setq startedInVP t)
);cond 2
);cond
;get elevations
(while (setq pt (getpoint "\nSelect point for Elevation (Enter to quit): "))
(setq elev (caddr pt))
(prompt (strcat "\nElevation: " (rtos elev 2 2)))
);while
;finish up
(if (and (= 0 tm) (not startedInVP)) (command "_.PSPACE"))
(prompt "\nGZ Complete.")
(princ)
);defun
That's the best I'm going to be able to do. Wish I could do more!
Best,
~DD