TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Slim© on April 20, 2004, 04:51:48 PM
-
Hey all,
Hope you can help. I'm trying to select a viewport to be the current one within LISP.
I'm working on a small routine for one of my coworkers. It inserts a basrscale and a north arrow in paperspace, rotating the north arrow to north.
He has however more than one viewport. The one most recently used may not be the viewport he want's the north arrow to reference, as he is working on Civil Plan & Profile drawings.
Any help would be appreciated. Thanks in advance. :D
-
Maybe this will help.
(setvar "TileMode" 0) ; Force PaperSpace
(setq vpFlag (getvar "cvport")) ; get viewport #
(While (= vpFlag 1) ; No active viewport, Loop until one is picked
(setq sel-vport (car (entsel "\nSelect view port: ")))
(if (= sel-vport nil)
(alert
"You must select a viewport\n --=< Try again! >=--"
)
(progn
(setq entvport (entget sel-vport))
(if (= (cdr (assoc 0 entvport)) "VIEWPORT")
(progn
(setq vpFlag (cdr (assoc 69 entvport))
)
(command "mspace")
(setvar "cvport" vpFlag)
) ; endif viewport
)
)
) ; endif cond sel-vport
) ;endwhile (= vpFlag 1)
-
That worked GREAT. :D
Thanks CAB
-
This piece of lisp works very well, except when you try to select a irregularly shaped viewport. Then it selects the ployline associated with the viewport.
I've tried to move the polyline to the back, but that doesn't work.
Any suggestions?
Thanks for all your help.
-
(setq ss (ssget '((0 . "viewport"))))
If thats not enough of a hint .. then yell.
-
THX Kerry.
-
Slim, Kerry-
Here's what I came up with to allow the (entsel) to work with irregular viewports.
(setq obj (entget (car obj)))
(if (and
(= (cdr (assoc 0 obj)) "LWPOLYLINE")
(setq vptest (member '(102 . "{ACAD_REACTORS") obj))
(setq vptest (member '(102 . "}") (reverse vptest)))
(assoc 330 vptest)
)
(setq obj (entget (cdr (assoc 330 vptest))))
)
Jeff
-
Very nice, Jeff.
Been bangin' my head against this all morning, I'll still keep workin' on it, by way of my train of thought. Gotta learn this somehow.
Thanks for your input.
-
This seemed to work for me.
Irrigular viewports may be objects other than LWpolylines.
(defun c:test ()
(setvar "TileMode" 0) ; Force PaperSpace
(if (/= (getvar "cvport") 1)
(command "_pspace") ; close the view port
)
(setq vpflag (getvar "cvport")) ; get viewport #
(while (= vpflag 1) ; No active viewport, Loop until one is picked
(setq sel-vport (car (entsel "\nSelect view port: ")))
(if (= sel-vport nil)
(alert "You must select a viewport\n --=< Try again! >=--")
(progn
(setq entvport (entget sel-vport))
(if (and;; not all vp objects are LWPolylines
;;(= (cdr (assoc 0 entvport)) "LWPOLYLINE")
(setq vptest (member '(102 . "{ACAD_REACTORS") entvport))
(setq vptest (member '(102 . "}") (reverse vptest)))
(assoc 330 vptest)
)
(setq entvport (entget (cdr (assoc 330 vptest))))
)
(if (= (cdr (assoc 0 entvport)) "VIEWPORT")
(progn
(setq vpflag (cdr (assoc 69 entvport))
)
(command "mspace")
(setvar "cvport" vpflag)
) ; endif viewport
)
)
) ; endif cond sel-vport
) ;endwhile (= vpFlag 1)
)
-
CAB you are AWESOME!!! Very, very nice, THX. :D
-
Your welcome..
And Thanks to Jeff Mishler for leading the way. :)
CAB
-
Your welcome..
And Thanks to Jeff Mishler for leading the way. :)
CAB
Quite true, thanks again Jeff
-
You are all welcome! And my thanks to CAB, as I wasn't aware that irregular viewports could be something other than a LWPolyLine ( I don't use them much)
:D :D :D
Jeff
-
Congrats DAD. :)
I use them sparingly but i do use a CIRCLE for magnified details.
CAB
-
Very nice to know, thanks CAB.
-
Well all,
Got what I wanted. It seems to work very well. Basically, what is does is insert both a North arrow, and a barscale into paperspace by selecting a viewport.
Heres the code:
;| C:BS C:BARSCALE
This routine inserts both the North arrow and the Barscale into a drawing
They are placed in PaperSpace at a selected location
The Barscale information is filled in based upon the current viewport scale
The North arrow is rotated based upon the current viewport's viewtwist
Viewport selection portion by CAB on 04-20-2004 & 06-08-2004.
He can be found swimming in The Swamp (http://theswamp.org/phpBB2/)
|;
(defun RTOD (R)
(* 180.0 (/ R pi))
)
(defun DTOR (deg)
(* deg 0.017453292519943)
)
(defun C:BS ( / APP-DATA ENAME ELST EELST SCL1 SCL2 SCMS)
(if (null SF)
(setq SF (getvar "ltscale"))
);end if
(setq PTA (getpoint "\nPick insertion point for Barscale/North Arrow: "))
(defun APP-DATA (E1 APP) (cdadr (assoc -3 (entget E1 (list APP)))));end defun APP-DATA
(setq VPF (getvar "cvport")) ; get viewport #
(while (= VPF 1) ; No active viewport, Loop until one is picked
(setq SLVP (car (entsel "\nSelect view port: ")))
(if (= SLVP nil)
(alert "You must select a viewport\n --=< Try again! >=--")
(progn
(setq ENTVPORT (entget SLVP))
(if (and;; not all vp objects are LWPolylines
(setq VPTEST (member '(102 . "{ACAD_REACTORS") ENTVPORT))
(setq VPTEST (member '(102 . "}") (reverse VPTEST)))
(assoc 330 VPTEST)
)
(setq ENTVPORT (entget (cdr (assoc 330 VPTEST))))
)
(if (= (cdr (assoc 0 ENTVPORT)) "VIEWPORT")
(progn
(setq VPF (cdr (assoc 69 ENTVPORT))
)
(command "mspace")
(setvar "cvport" VPF)
) ; endif viewport
)
)
) ; endif cond SLVP
(if (= (cdr (assoc 0 ENTVPORT)) "VIEWPORT")
(progn
(setq EELST (APP-DATA (cdr (assoc -1 ENTVPORT)) "ACAD"))
(setq SCL1 (cdr (nth 6 EELST)) SCL2 (cdr (assoc 41 ENTVPORT)) SCMS (/ SCl1 SCl2))
);end progn
);end if
) ;endwhile (= VPF 1)
(setq FACT (RTOD (getvar "viewtwist")))
(command "PSPACE")
(command "insert" "X_BSCALE" PTA 1 1 0 (rtos SCMS 2 0) (rtos SCMS 2 0) (rtos (/ SCMS 2) 2 0) (rtos (* 2 SCMS) 2 0) (rtos SCMS 2 0))
(command "insert" "X_NORTH" (polar PTA (DTOR 90) 1.75) 1 1 FACT)
(princ)
);end defun C:BARSCALE
(defun C:BARSCALE () (C:BS))
(prompt "\n{1.1}Barscale/North Arrow BS ")
(princ)
Thanks again CAB, what you did in a "nut Shell" was to reverse the list, so that the viewport was the first entity selected.