Author Topic: Select/Set current viewport  (Read 8140 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: 4094
  • 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: 4094
  • 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....