Toggle Viewport On/Off

Toggle Viewport On/Off

Jonathan3891
Advisor Advisor
1,068 Views
4 Replies
Message 1 of 5

Toggle Viewport On/Off

Jonathan3891
Advisor
Advisor

I am looking to create a lisp file that will toggle a selected viewport on/off.

I've done a lot of searching but haven't found anything similar to what I'm trying to do.

 

This is all I have so far but its not working. My idea was to see if I could have it show an alert if the viewport was on or off and build off that, but I'm stuck and I'm not entirely sure I'm going about this the right way.

(vl-load-com)
(defun c:ttt (/ )
  (setq VP (ssget))
  (setq targetvp (vlax-ename->vla-object (ssname VP 0)))
  (if (=(vla-display targetvp :vlax-true))
    (alert "true")
    )
  (alert "false")
  )

 


Jonathan Norton
Blog | Linkedin
0 Likes
Accepted solutions (1)
1,069 Views
4 Replies
Replies (4)
Message 2 of 5

ronjonp
Mentor
Mentor

You need to use: vla-put-ViewportOn

0 Likes
Message 3 of 5

ronjonp
Mentor
Mentor
Accepted solution

Here's a quick example:

(defun c:foo (/ o s)
  ;; RJP » 2019-07-26
  ;; Toggle viewport on status
  (if ;; Filter viewport objects
      (setq s (ssget ":L" '((0 . "viewport"))))
    ;; Iterate over selection set
    (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
      ;; Convert to vla-object
      (setq o (vlax-ename->vla-object x))
      ;; Toggle on off status
      (vlax-put o 'viewporton (boole 8 0 (vlax-get o 'viewporton)))
    )
  )
  (princ)
)
(vl-load-com)

 2019-07-26_8-40-55.gif

Message 4 of 5

Jonathan3891
Advisor
Advisor
That's exactly what I was looking for!

I new I was going about this the wrong way. I'm still learning LISP and fairly new to VLA.

Thank you!!!

Jonathan Norton
Blog | Linkedin
0 Likes
Message 5 of 5

ronjonp
Mentor
Mentor

Glad to help 🙂

0 Likes