Jump to content
Emmanuel Delay

generate visibility states

Recommended Posts

Emmanuel Delay

Is there a way for LISP to generate visibility states?

If yes... then maybe import the block definition, from dwg file (1 file = 1 block)


I'm combining lots of blocks into fewer blocks, by category.


(Google completely ignores the "generate" or "create" search term. I find lots of "set dynamic state" links)

Share this post

Link to post
Share on other sites
Stefan BMR

Not sure exactly how it is supposed to work, or what objects do you want to add to a specific visibility, so try this one, as an example.

First, insert some static blocks into your drawing.

Then run the lisp and select the blocks. The lisp will create a new block with Vis States, each one representing one of the selected blocks.

Here it is, quick and dirty.

;Create Dynamic Block w/ visibility
;Stefan M. 10.08.2018
(defun c:test ( / msg ss nb i bn lst)
     (setq ss (ssget '((0 . "INSERT"))))
     (setq nb (getstring "\nSpecify new block name: "))
     (setq msg "\nInvalid name")
     (snvalid nb)
     (setq msg "\nBlock already defined")
     (not (tblsearch "block" nb))
     (repeat (setq i (sslength ss))
       (setq bn (cdr (assoc 2 (entget (ssname ss (setq i (1- i)))))))
       (if (not (member bn lst))
         (setq lst (cons bn lst))
     (command "_bedit" nb)
     (command "_bparameter" "_visibility" '(0.0 -10 0.0) "1")
     (foreach x lst
       (command "_bvstate" "_new" x "_hide")
       (entmakex (list '(0 . "INSERT") (cons 2 x) '(10 0.0 0.0 0.0)))
     (command "_bvstate" "_set" (car lst))
     (command "_bvstate" "_delete" "VisibilityState0")
     (command "_bsave")
     (command "_bclose")
     (command "_insert" nb "_s" 1.0 "_r" 0.0)
     (while (> (getvar 'cmdactive) 0)
       (command pause)
   (if msg (alert msg))



PS. The lisp is working on my computer. However, it might need some checking routines. For example, I can imagine, if you use a non-english autocad, the default name of the first visibility state might not be "VisibilityState0", so my lisp could fail trying to delete it.

Share this post

Link to post
Share on other sites
Emmanuel Delay

Thanks. Looks exactly like what I need.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now