Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Viewport toggle lsp

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
Postmaster_G
1801 Views, 10 Replies

Viewport toggle lsp

Cat HappyHello everyone!

 

So i currently have a lsp that I can toggle a few snaps with:

 

(defun c:OSnapPolarOTrackToggle (/)
  (setvar 'AUTOSNAP (boole 6 (getvar 'AUTOSNAP) 24))
  (setvar 'OSMODE (boole 6 (getvar 'OSMODE) 16384))
  (princ)
)

 

I someone helped me before as I am not very familiar with how to program in lsp.

 

I would like to make a button that will toggle all viewports to be locked/unlocked.

 

I noticed that there are commands in Civil3D [and probably vanilla] that can do this.

 

Is it possible to make a lisp that will toggle this function?

 

something like...

 

 

(defun c:VPLockToggle (/)

^C^C-VPORTS;LOCK;ON;ALL;;

^C^C-VPORTS;LOCK;OFF;ALL;;

ETC.....

 

^as you can see i have no idea what to do with this!

 

I promise I will learn lsp soon!!!

 

 

 

 

-Meow
10 REPLIES 10
Message 2 of 11
Postmaster_G
in reply to: Postmaster_G

In addition, I have noticed that the lock and unlock commands only apply to the current layout, not all layouts.

 

I would like to be able to toggle the viewport lock on all layouts with the click of a custom button like i have for my snaps.

 

For the snaps, I can use F3 or the button that I made.

 

For the viewport lock, I would be happy with an alias (VV, LO etc) or a button.

 

Thank You!!!!!

-Meow
Message 3 of 11
Postmaster_G
in reply to: Postmaster_G

So I found this code by Lee-Mac that seems to be pretty good!

 

What I did was change the last two aliases that he has below to VU and VV for unlock all and lock all respectively (items highlighted in red)

These were not currently in use by cad.

Then I created two new command, one with macro '_VU and one with macro '_VV.

I used the default viewport lock button icon for the lock button, and then edited it and saved it for and unlock icon.

Pretty good, but I still think it would be cool to be able to have only these two functions as a toggle with one button.

 

locks.PNG 

 

"(defun c:vpla nil"
 
 
"(defun c:vpua nil ;; changed "VPLU" to "VPUA" to be consistant with the above function"
 
By Lee-Mac found at the Augi forums

 

;; Lock Selected Viewport

 

(vl-load-com)

 

(defun c:vpl nil

 

(if (SSVPLock (ssget "_+.:E:S:L" '((0 . "VIEWPORT"))) :vlax-true)

 

(princ "\n--> Viewport Locked.")

 

)

 

(princ)

 

)

 

;; Unlock Selected Viewport

 

(defun c:vpu nil

 

(if (SSVPLock (ssget "_+.:E:S:L" '((0 . "VIEWPORT"))) :vlax-false)

 

(princ "\n--> Viewport Unlocked.")

 

)

 

(princ)

 

)

 

;; Lock All Viewports

 

(defun c:vpla nil

 

(SSVPLock (ssget "_X" '((0 . "VIEWPORT"))) :vlax-true)

 

(princ "\n--> All Viewports Locked.")

 

(princ)

 

)

 

;; Unlock All Viewports

 

(defun c:vpua nil ;; changed "VPLU" to "VPUA" to be consistant with the above function

 

(SSVPLock (ssget "_X" '((0 . "VIEWPORT"))) :vlax-false)

 

(princ "\n--> All Viewports UnLocked.")

 

(princ)

 

)

 

(defun SSVPLock ( ss lock / i )

 

(if ss

 

(repeat (setq i (sslength ss))

 

(vla-put-displaylocked (vlax-ename->vla-object (ssname ss (setq i (1- i)))) lock) t

 

)

 

)

 

)

 

-Meow
Message 4 of 11
hmsilva
in reply to: Postmaster_G

A different approach for toggle all viewports lock/unlock

(defun c:tvp ( / )
  (vl-load-com)
  (vlax-for layt (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
    (if	(eq :vlax-false (vla-get-modeltype layt))
      (vlax-for	obj (vla-get-block layt)
	(if (= (vla-get-objectname obj) "AcDbViewport")
	  (vlax-put obj 'displaylocked (~ (vlax-get obj 'displaylocked)))
	)
      )
    )
  )
  (princ)
)

HTH

Henrique

EESignature

Message 5 of 11
Postmaster_G
in reply to: Postmaster_G

Smiley HappyThis only seems to lock/unlock all viewports in my current/active layout.

Viewports in other layout tabs seem unaffected?

 

Was that your intent?

 

Your routine works well though.

-Meow
Message 6 of 11
Postmaster_G
in reply to: Postmaster_G

I was wrong, it does work for all viewports!

 

Actually, you totally nailed it!!!

 

This is what I was looking for.

 

THANK YOU VERY MUCH - I would give you multiple Kudos if I could!

 

\|'0'|/

-Meow
Message 7 of 11
hmsilva
in reply to: Postmaster_G

You're welcome, Postmaster_G
Glad I could help

Henrique

EESignature

Message 8 of 11
msarqui
in reply to: hmsilva

Hi Henrique,

 

Could it be upgrade to ignore viewports in a specific layer, or better yet, in a list of layers? For exemple, the layer Tx-XNplot and the layer WIN?

 

Thanks,

Marcelo

Message 9 of 11
hmsilva
in reply to: msarqui


@msarqui wrote:

Hi Henrique,

 

Could it be upgrade to ignore viewports in a specific layer, or better yet, in a list of layers? For exemple, the layer Tx-XNplot and the layer WIN?

 

Thanks,

Marcelo


Hi Marcelo,

try this modified code

 

(vl-load-com)
(defun c:tvp (/)
   (vlax-for layt (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
      (if (eq :vlax-false (vla-get-modeltype layt))
         (vlax-for obj (vla-get-block layt)
            (if (and (= (vla-get-objectname obj) "AcDbViewport")
                     (not (wcmatch (strcase (vla-get-layer obj)) "TX-XNPLOT,WIN"))
                )
               (vlax-put obj 'displaylocked (~ (vlax-get obj 'displaylocked)))
            )
         )
      )
   )
   (princ)
)

 

EDIT: did the other code works as expected, or not?

 

Hope this helps,
Henrique

EESignature

Message 10 of 11
msarqui
in reply to: hmsilva

Yes Henrique.

The other and this one are working pretty well. It took me time because we have 19 templates in the office and I needed to test in each one.

Thanks again for your help!

Marcelo

Message 11 of 11
hmsilva
in reply to: msarqui

You're welcome, Marcelo
Glad I could help

Henrique

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost