Author Topic: How to open the selected viewport ?  (Read 5571 times)

0 Members and 1 Guest are viewing this topic.

Coder

  • Swamp Rat
  • Posts: 827
How to open the selected viewport ?
« on: May 06, 2011, 07:06:31 AM »
Hello ,

I wonder how to open the selected viewport by lisp, and to use (command "_.mspace") would not get the required one opened.

Any help would be appreciated .


Thanks

kruuger

  • Swamp Rat
  • Posts: 637
Re: How to open the selected viewport ?
« Reply #1 on: May 06, 2011, 07:18:27 AM »
hi coder,

you can grab some info from here:
Code: [Select]
   (defun c:TEST (/ SS KEY C)
      (if
        (setq SS
          (ssget "_X"
            (list
              (cons 0 "VIEWPORT")
              (cons 410 (getvar 'CTAB))
            )
          )
        )
        (progn
          (setq C 0)
          (vla-put-MSpace (jk:ACX_ActDoc) :vlax-true)
          (kr:TEST_ActivateViewport)
          (princ "\nPrzełącz rzutnie [+/-/Exit] <Exit> ")
          (while
            (/= (setq KEY (jk:CRV_GetKey)) "Exit")
            (princ "\nPrzełącz rzutnie [+/-/Exit] <Exit> ")
            (cond
              ( (= KEY "+")
                (setq C (1+ C))
                (if (> C (- (sslength SS) 2))
                  (progn
                    (setq C 0)
                    (kr:TEST_ActivateViewport)
                  )
                  (progn
                    (kr:TEST_ActivateViewport)
                  )
                )
              )
              ( (= KEY "-")
                (setq C (1- C))
                (if (< C 0)
                  (progn
                    (setq C (- (sslength SS) 2))
                    (kr:TEST_ActivateViewport)
                  )
                  (progn
                    (kr:TEST_ActivateViewport)
                  )
                )
              )
            )
          )
        )
        (princ "\n** Brak rzutni w aktualnym obszarze papieru **")
      )
      (princ)
    )
    ; ============================================================ ;
    ; Activate viewport                                            ;
    ; ============================================================ ;
    (defun kr:TEST_ActivateViewport ()
      (vla-Put-ActivePViewport
        (kr:ACX_ADoc)
        (vlax-Ename->vla-Object (ssname SS C))
      )
    )
    ; ============================================================ ;
    ; Get keyboard input                                           ;
    ; ============================================================ ;
    (defun jk:CRV_GetKey (/ TST)
      (if
        (setq TST (grread nil 2))
        (cond
          ( (= (car TST) 3)(jk:CRV_GetKey))
          ( (= (car TST) 2)
            (cond
              ( (= (cadr TST) 43) "+")
              ( (= (cadr TST) 45) "-")
              ( (if (member (cadr TST) (list 13 32 69 101)) "Exit"))
            )
          )
          (equal TST '(25 298) "Exit")
          (T (jk:CRV_GetKey))
        )
      )
    )
    (princ)
« Last Edit: May 06, 2011, 08:30:06 AM by kruuger »

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: How to open the selected viewport ?
« Reply #2 on: May 06, 2011, 07:37:02 AM »
Nice one Kruuger  8-)

Another, simple example:

Code: [Select]
(defun c:test ( / sel ) (vl-load-com)

  (or acdoc (setq acdoc (vla-get-activedocument (vlax-get-acad-object))))

  (if (setq sel (ssget "_+.:S:E:L" '((0 . "VIEWPORT"))))
    (progn
      (vla-put-mspace acdoc :vlax-true)
      (vla-put-activepviewport acdoc (vlax-ename->vla-object (ssname sel 0)))
    )
  )
  (princ)
)

kruuger

  • Swamp Rat
  • Posts: 637
Re: How to open the selected viewport ?
« Reply #3 on: May 06, 2011, 07:42:15 AM »
Nice one Kruuger  8-)

Another, simple example:

Code: [Select]
(defun c:test ( / sel ) (vl-load-com)

  (or acdoc (setq acdoc (vla-get-activedocument (vlax-get-acad-object))))

  (if (setq sel (ssget "_+.:S:E:L" '((0 . "VIEWPORT"))))
    (progn
      (vla-put-mspace acdoc :vlax-true)
      (vla-put-activepviewport acdoc (vlax-ename->vla-object (ssname sel 0)))
    )
  )
  (princ)
)
thanks Lee, but your exactly hit the point  :-)
kruuger

Coder

  • Swamp Rat
  • Posts: 827
Re: How to open the selected viewport ?
« Reply #4 on: May 06, 2011, 07:55:42 AM »
Thanks a lot guys , it is really appreciated a lot.

Lee .

Why did you use *or* at the beginning of codes ?

Thanks.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: How to open the selected viewport ?
« Reply #5 on: May 06, 2011, 08:05:45 AM »
Why did you use *or* at the beginning of codes ?

Because the variable 'acdoc' is intentionally global to avoid repeated calls to vlax-get-acad-object since this process is time consuming.

Hence, using the 'or' function, I test the symbol 'acdoc' for a non-nil value, and, if nil, I bound the ActiveDocument object to it. Note that 'or' will keep evaluating supplied arguments until an argument returns a non-nil value.

Lee

Coder

  • Swamp Rat
  • Posts: 827
Re: How to open the selected viewport ?
« Reply #6 on: May 06, 2011, 08:15:45 AM »
That's great Lee.

And besides that, that's why you did not localized it . correct ?  :-)

Thanks

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: How to open the selected viewport ?
« Reply #7 on: May 06, 2011, 08:17:39 AM »
And besides that, that's why you did not localized it . correct ?  :-)

Correct, the 'acdoc' symbol is global - i.e. it resides in the document namespace rather than the function namespace.

kruuger

  • Swamp Rat
  • Posts: 637
Re: How to open the selected viewport ?
« Reply #8 on: May 06, 2011, 08:31:10 AM »
when you guys talk about variable i noticed that one subroutine was missing for my code:
Code: [Select]
; ============================================================ ;
; Retrieves pointers to the active document                    ;
; ============================================================ ;
(defun kr:ACX_ADoc ()
  (or
    *kr-ADoc
    (setq *kr-ADoc (vla-Get-ActiveDocument (vlax-Get-Acad-Object)))
  )
  *kr-ADoc
)
k.

Coder

  • Swamp Rat
  • Posts: 827
Re: How to open the selected viewport ?
« Reply #9 on: May 06, 2011, 08:35:43 AM »
And besides that, that's why you did not localized it . correct ?  :-)

Correct, the 'acdoc' symbol is global - i.e. it resides in the document namespace rather than the function namespace.

Great .

Thanks a lot Lee.

Coder

  • Swamp Rat
  • Posts: 827
Re: How to open the selected viewport ?
« Reply #10 on: May 06, 2011, 08:37:14 AM »
when you guys talk about variable i noticed that one subroutine was missing for my code:
Code: [Select]
; ============================================================ ;
; Retrieves pointers to the active document                    ;
; ============================================================ ;
(defun kr:ACX_ADoc ()
  (or
    *kr-ADoc
    (setq *kr-ADoc (vla-Get-ActiveDocument (vlax-Get-Acad-Object)))
  )
  *kr-ADoc
)
k.

Thanks for your interests kruuger .

Highly appreciated.

Coder

  • Swamp Rat
  • Posts: 827
Re: How to open the selected viewport ?
« Reply #11 on: May 06, 2011, 11:14:11 AM »
I have got to ask about how to deactivate the selected viewport as well . :-(

Thanks.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: How to open the selected viewport ?
« Reply #12 on: May 06, 2011, 11:20:18 AM »
Code: [Select]
(vla-put-mspace <DocumentObject> :vlax-false)

Coder

  • Swamp Rat
  • Posts: 827
Re: How to open the selected viewport ?
« Reply #13 on: May 06, 2011, 11:32:33 AM »
Code: [Select]
(vla-put-mspace <DocumentObject> :vlax-false)

But that did not close the viewport  !!!  :oops:

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: How to open the selected viewport ?
« Reply #14 on: May 06, 2011, 11:34:48 AM »
Code: [Select]
(vla-put-mspace <DocumentObject> :vlax-false)

But that did not close the viewport  !!!  :oops:

How are you implementing it?