Lock All Viewports ~ Lisp

It never fails! Every time I have to work on somebody else’s drawings, their viewports are never locked! I got tired of click every viewport and locking them manually, so I created this lisp!


(defun c:vpl (/ kw kval doc adoc lao cnt inc cvprt blk pw)
   (vl-load-com)
   (initget 1 "LOCK UNLOCK")
   (setq kw (getkword "\nLOCK or UNLOCK ALL VPORTS [LOCK/UNLOCK]: "))
   (setq kw (strcase kw))
      (if (= kw "LOCK")
      (setq kval :vlax-true)
      (if (= kw "UNLOCK")
      (setq kval :vlax-false)
	)
	)
(setq doc (vlax-get-object "AutoCad.Application")
adoc (vla-get-ActiveDocument doc)
lao (vla-get-Layouts adoc)
cnt (vla-get-Count lao)
inc 0
)
(repeat cnt
(setq cvprt (vla-Item lao inc)
inc (+ inc 1)
blk (vla-get-Block cvprt)
)
(vlax-for itm blk
(if
(vlax-property-available-p itm 'DisplayLocked)
(progn
(vla-put-DisplayLocked itm kval)
(vla-update itm)
)
)
)
)
(princ)
)
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s