Author Topic: Select/Set current viewport  (Read 8138 times)

0 Members and 1 Guest are viewing this topic.

Slim©

  • Needs a day job
  • Posts: 6566
  • The Dude Abides...
Select/Set current viewport
« Reply #15 on: June 09, 2004, 06:06:24 PM »
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:
Code: [Select]
;| 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.
I drink beer and I know things....