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

0 Members and 1 Guest are viewing this topic.

Slim©

  • Needs a day job
  • Posts: 6566
  • The Dude Abides...
Select/Set current viewport
« 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
I drink beer and I know things....

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Select/Set current viewport
« Reply #1 on: April 20, 2004, 06:32:05 PM »
Maybe this will help.

Code: [Select]
 (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)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Slim©

  • Needs a day job
  • Posts: 6566
  • The Dude Abides...
Select/Set current viewport
« Reply #2 on: April 20, 2004, 06:35:02 PM »
That worked GREAT. :D

Thanks CAB
I drink beer and I know things....

Slim©

  • Needs a day job
  • Posts: 6566
  • The Dude Abides...
Select/Set current viewport
« Reply #3 on: June 04, 2004, 07:40:37 PM »
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.
I drink beer and I know things....

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Select/Set current viewport
« Reply #4 on: June 05, 2004, 10:51:38 AM »
(setq ss (ssget '((0 . "viewport"))))


If thats not enough of a hint .. then yell.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Slim©

  • Needs a day job
  • Posts: 6566
  • The Dude Abides...
Select/Set current viewport
« Reply #5 on: June 06, 2004, 02:10:49 AM »
THX Kerry.
I drink beer and I know things....

Jeff_M

  • King Gator
  • Posts: 4095
  • C3D user & customizer
Select/Set current viewport
« Reply #6 on: June 07, 2004, 02:36:50 PM »
Slim, Kerry-
Here's what I came up with to allow the (entsel) to work with irregular viewports.
Code: [Select]

(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

Slim©

  • Needs a day job
  • Posts: 6566
  • The Dude Abides...
Select/Set current viewport
« Reply #7 on: June 07, 2004, 03:53:38 PM »
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.
I drink beer and I know things....

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Select/Set current viewport
« Reply #8 on: June 07, 2004, 06:18:04 PM »
This seemed to work for me.
Irrigular viewports may be objects other than LWpolylines.

Code: [Select]
(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)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Slim©

  • Needs a day job
  • Posts: 6566
  • The Dude Abides...
Select/Set current viewport
« Reply #9 on: June 07, 2004, 08:12:56 PM »
CAB you are AWESOME!!! Very, very nice, THX. :D
I drink beer and I know things....

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Select/Set current viewport
« Reply #10 on: June 07, 2004, 08:27:05 PM »
Your welcome..

And Thanks to Jeff Mishler for leading the way. :)

CAB
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Slim©

  • Needs a day job
  • Posts: 6566
  • The Dude Abides...
Select/Set current viewport
« Reply #11 on: June 07, 2004, 08:41:22 PM »
Quote from: CAB
Your welcome..

And Thanks to Jeff Mishler for leading the way. :)

CAB


Quite true, thanks again Jeff
I drink beer and I know things....

Jeff_M

  • King Gator
  • Posts: 4095
  • C3D user & customizer
Select/Set current viewport
« Reply #12 on: June 08, 2004, 11:42:45 AM »
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

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Select/Set current viewport
« Reply #13 on: June 08, 2004, 12:12:00 PM »
Congrats DAD. :)

I use them sparingly but i do use a CIRCLE for magnified details.

CAB
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Slim©

  • Needs a day job
  • Posts: 6566
  • The Dude Abides...
Select/Set current viewport
« Reply #14 on: June 08, 2004, 12:18:13 PM »
Very nice to know, thanks CAB.
I drink beer and I know things....

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....