error: bad argument type: VLA-OBJECT nil

error: bad argument type: VLA-OBJECT nil

Anonymous
Not applicable
1,882 Views
3 Replies
Message 1 of 4

error: bad argument type: VLA-OBJECT nil

Anonymous
Not applicable

I have been using a lisp: VPL VPU, this lisp will unlock or lock all viewports in a file. On some of my files, it works great, but on others, I receive this error, "error: bad argument type: VLA-OBJECT nil", I do not know how to fix this. Any help would be appreciated.

Here is the lisp:

 

Lock/Unlock Viewports Shortcut

;;Program by Dann Brower 2006
(defun C:vpl (/ kw)
(setq kw "LOCK")
(vplocks kw)
(princ)
)
(defun C:vpu (/ kw)
(setq kw "UNLOCK")
(vplocks kw)
(princ)
)
(defun vpLocks (kw / kval doc adoc lao cnt inc cvprt blk pw)
(vl-load-com)
(setq *doc* (vla-get-activedocument (vlax-get-acad-object)))
(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)
)

 

Thanks for any help.

0 Likes
Accepted solutions (1)
1,883 Views
3 Replies
Replies (3)
Message 2 of 4

ronjonp
Advisor
Advisor
Accepted solution

That code seems to work fine here. Here is another that I've been using successfully for about 15 years now :).

(defun c:vpl (/ lck opt vps)
  ;; RJP » 2021-01-19
  (cond	((setq vps (setq vps (ssget "_X" '((0 . "VIEWPORT") (-4 . "!=") (69 . 1)))))
	 (initget 0 "Lock Unlock")
	 (setq opt (cond ((getkword (strcat "\nAll Viewports [Lock/Unlock] <Lock>: ")))
			 ("Lock")
		   )
	 )
	 (setq lck (cond ((= opt "Lock") -1)
			 (0)
		   )
	 )
	 (foreach x (mapcar 'cadr (ssnamex vps))
	   (vl-catch-all-apply 'vlax-put (list (vlax-ename->vla-object x) 'displaylocked lck))
	 )
	)
	((princ "\nNo viewports found..."))
  )
  (princ)
)
Message 3 of 4

Anonymous
Not applicable

That lisp worked great!!😀

Thanks

0 Likes
Message 4 of 4

ronjonp
Advisor
Advisor

@Anonymous wrote:

That lisp worked great!!😀

Thanks


Glad to help 🍻

0 Likes