Further to my earlier topic for getting the viewport scale which has been nicely solved, I am looking for a way to get one of the corners of the viewport outline 'drawn' in modelspace so that I can add the name of the spcific layout Tab to which it relates in a location that suits the drawn outline.
The code that I am adapting came from the thread titled Outline projection all viewports to model
The routine appears to pick up the corners of the viewport in paperspace and tranform/translate them to modelspace co-ordinates.
The code is as follows:-
(defun c:VPO (/ _trans _cornersFromBBox ss i ent data ent2 lst) ;; Viewport Outline ;; Require subroutine: PCS2WCS (and all subs it requires) ;; PCS2WCS by gile (http://www.theswamp.org/index.php?topic=29231.msg347755#msg347755) ;; Alan J. Thompson, 12.08.11
(vl-load-com)
(defun _trans (p) (cons 10 (PCS2WCS p ent))) (defun _cornersFromBBox (o / a b) (vla-getboundingbox o 'a 'b) (setq a (_trans (vlax-safearray->list a)) b (_trans (vlax-safearray->list b)) ) (list a (list (car a) (cadr a) (caddr b)) b (list (car b) (cadr b) (caddr a))) ) (if (setq ss (ssget '((0 . "VIEWPORT")))) (repeat (setq i (sslength ss)) (setq ent (ssname ss (setq i (1- i))) data (entget ent) ) (if (if (setq ent2 (cdr (assoc 340 data))) (setq lst (apply 'append (mapcar '(lambda (x) (if (eq (car x) 10) (list (_trans (cdr x))) ) ) (entget ent2) ) ) ) (setq lst (_cornersFromBBox (vlax-ename->vla-object ent))) ) (entmakex (append (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") (cons 90 (length lst)) '(70 . 1) '(410 . "Model") ) lst ) ) ) ) ) (princ) )
but I haven't included the gile subroutines here - I am assuming that they won't necessarily help with my query. If they are necessary, they can be accessed via the original thread shown above.
--
Gordon
Solved! Go to Solution.
Solved by skintsubby. Go to Solution.
Here's an old one I had (I can't remember where I got it) it draws a Polyline in MS size as the viewport you are currently in. You can easily modify it.
It's nothing like how I'd do it now, but it might help.
(defun c:drawview(/
sav_os, cpt, vx, vy, ly, scr, scx, scy,
lx, hlx, hly, lowerlimitx, lowerlimity, upperlimitx, upperlimity, lowerlimit, upperlimit, topleft, bottomright
)
(setq sav_os (getvar "osmode"))
(setq sav_cmd (getvar "cmdecho"))
(setvar "osmode" 0)
(setvar "cmdecho" 0)
(command "ucs" "d" "tempview")
(command "ucs" "s" "tempview")
(command "ucs" "v")
(setq
cpt (getvar "VIEWCTR")
vx (car cpt)
vy (cadr cpt)
ly (getvar "VIEWSIZE")
scr (getvar "SCREENSIZE")
scx (car scr)
scy (cadr scr)
lx (* scx (/ ly scy))
hlx (/ lx 2.0)
hly (/ ly 2.0)
lowerlimitx (- vx hlx) ;;lower limit x
lowerlimity (- vy hly) ;;lower limit y
upperlimitx (+ vx hlx) ;;upper limit x
upperlimity (+ vy hly) ;;upper limit y
lowerlimit (list lowerlimitx lowerlimity) ;;lower limit = bl
upperlimit (list upperlimitx upperlimity) ;;upper limit = tr
topleft (list lowerlimitx upperlimity) ;;top left
bottomright (list upperlimitx lowerlimity) ;;bottom right
);setq
(command "layer" "t" "defpoints" "m" "defpoints" "")
(command "pline" lowerlimit bottomright upperlimit topleft "c")
(command "ucs" "r" "tempview")
(command "ucs" "d" "tempview")
(setvar "osmode" sav_os)
(setvar "cmdecho" sav_cmd)
(princ)
)
Thanks skintsubby (UK based BTW?),
I'll take a look at that one and see how it can work for me. A completely different approach for sure, but still fairly logical.
--
Gordon
Added in saving the current layer and restoring after, and will be able to change to my preferred layer for the 'view' as well as one or two other odd tweaks and it will do exactly what I want.
So again, thanks for the routine - does just what I need.
--
Gordon