Extract a dynamic block complete visstate list

Extract a dynamic block complete visstate list

timothy_crouse
Collaborator Collaborator
1,834 Views
10 Replies
Message 1 of 11

Extract a dynamic block complete visstate list

timothy_crouse
Collaborator
Collaborator

Hello

 

I am in the process of updating a dynamic block with NUMEROUS visstates to include a block properties table to setup a menu system.

 

Does anyone have a lisp that will extract all the visstates to a text file or something of the sort?

 

Thanks in Advance

-Tim C.

0 Likes
Accepted solutions (2)
1,835 Views
10 Replies
Replies (10)
Message 2 of 11

CodeDing
Advisor
Advisor
Accepted solution

@timothy_crouse ,

 

Sure thing. Here you go, this should work:

(defun c:TEST ( / e visibilities path f)
  (if (and (setq e (car (entsel "\nSelect dynamic block w/ visibilities: ")))
           (setq visibilities (GetVisibilities e)))
    (progn
      (setq path "c:\\users\\me\\my folder\\BlockVisibilities.txt")
      (setq f (open path "w"))
      (foreach v visibilities
        (write-line v f)
      );foreach
      (close f)
    );progn
  ;else
    (prompt "\nNo visibilities found.")
  );if
  (princ)
);defun

(defun GetVisibilities (blk / vList)
  ;blk - ename, of block w/ visibilities to retrieve
  (setq blk (vlax-ename->vla-object blk))
  (if (= (vla-get-isdynamicblock blk) :vlax-true)
    (foreach vis (vlax-get (car (vlax-invoke blk 'getdynamicblockproperties)) 'allowedvalues)
      (setq vList (cons vis vList))
    );foreach
  );if
);defun

 

NOTE: I'm not 100% savvy on my "vla-" functions so I'm sure there's room for improvement / other checks to perform.

 

Best,

~DD

Message 3 of 11

timothy_crouse
Collaborator
Collaborator

HOLY COW!

Nice work, very helpful.

 

Best Regards

-Tim C.

 

********************************************************************************************************************

Note to folks that wish to use this, be sure to edit the path in the lisp file and keep the "\\" convention

You can change the name in the top line too to have it launch with something other than "test"

 

-Attached to Thread renamed as VSX (visstate extraction pointing the output to "c:\temp"

 

Many thanks to CodeDing for this contribution

 

Message 4 of 11

timothy_crouse
Collaborator
Collaborator

Hello

 

If you have time could you take another look at the visstate extraction code.

 

It is generating errors when the lisp is run against the two blocks in the attached file.

 

Thanks in Advance

-Tim C.

0 Likes
Message 5 of 11

ronjonp
Mentor
Mentor
Accepted solution

It's because the values are numbers and they need to be strings to write to a file:

ronjonp_0-1662070938129.png

Note that the 'getvisibilities' function is only returning allowed values on the first item not all dynamic properties:

(car (vlax-invoke blk 'getdynamicblockproperties))

 

Try this mod, will export the following properties:

ronjonp_1-1662071855860.png

(defun c:test (/ e visibilities path f)
  (if (and (setq e (car (entsel "\nSelect dynamic block w/ visibilities: ")))
	   (setq visibilities (getvisibilities e))
      )
    (progn (setq path (strcat (getvar 'dwgprefix) "BlockVisibilities.txt"))
	   (setq f (open path "w"))
	   (foreach v visibilities (write-line (vl-princ-to-string v) f)) ;foreach
	   (close f)
    )					;progn
					;else
    (prompt "\nNo visibilities found.")
  )					;if
  (princ)
)					;defun

(defun getvisibilities (blk / vlist)	;blk - ename, of block w/ visibilities to retrieve
  (setq blk (vlax-ename->vla-object blk))
  (if (= (vla-get-isdynamicblock blk) :vlax-true)
    (foreach vis (vlax-invoke blk 'getdynamicblockproperties)
      (setq vlist (cons	(list (vlax-get vis 'propertyname)
			      (vlax-get vis 'value)
			      (vlax-get vis 'allowedvalues)
			)
			vlist
		  )
      )
    )					;foreach
  )					;if
)					;defun
 

 

 

Message 6 of 11

timothy_crouse
Collaborator
Collaborator

Sorry, not my swim lane.

 

This has worked on many of my other dynamic blocks. (dumping a visstate text file in c:temp with all the included visstates) that have numerous visstates. As far as I know I have set the door blocks up that same.  

 

What number are you referring to in your reply?

 

Thank You for looking at this

-Tim C.

0 Likes
Message 7 of 11

ronjonp
Mentor
Mentor

@timothy_crouse wrote:

Sorry, not my swim lane.

 

This has worked on many of my other dynamic blocks. (dumping a visstate text file in c:temp with all the included visstates) that have numerous visstates. As far as I know I have set the door blocks up that same.  

 

What number are you referring to in your reply?

 

Thank You for looking at this

-Tim C.


The numbers I'm referring to are the list on the right hand side of the image. Try the code I modified above and see if it gives you what you need.

0 Likes
Message 8 of 11

timothy_crouse
Collaborator
Collaborator

The lisp works on the blocks now.

 

Thank You for your help

-Tim C.

0 Likes
Message 9 of 11

Sea-Haven
Mentor
Mentor

I would get a copy of Lee-mac dynamic block defuns amongst them is getvisibilty. Plus the others are extremely helpful.

 Just a side note this will display visibility states as a choice when inserting dynamic block.

; Change dynamic block properties when inserting look at properties available.
; By Alan H June 2022

;; Get Dynamic Block Property Allowed Values  -  Lee Mac
;; Returns the allowed values for a specific Dynamic Block property.
;; Set Dynamic Block Visibility State  -  Lee Mac
;; Sets the Visibility Parameter of a Dynamic Block (if present) to a specific value (if allowed)
;; Get Visibility Parameter Name  -  Lee Mac
;; Returns the name of the Visibility Parameter of a Dynamic Block (if present)

(defun c:insdynv (blkname / pt obj lst ans)
(if (not LM:setdynpropvalue )(load "Dynamic block get-put"))
(setq pt (getpoint "\nPick a pt for block "))
(command "-insert" blkname "s" 1  pt 1  0)
(setq obj (vlax-ename->vla-object (entlast)))
(setq visval (LM:getvisibilityparametername obj))
(setq lst (LM:getdynpropallowedvalues obj visval))
(setq lst (cons "Please choose" lst))
(if (not AH:Butts)(load "Multi Radio buttons.lsp"))
(if (not AHbut)(setq AHbut 1))
(setq ans (ah:butts 1 "v"  lst))
(LM:SetVisibilityState obj ans)
(princ)
)


(defun c:insdynp ( / pt obj lst ans)
(if (not LM:setdynpropvalue )(load "Dynamic block get-put"))
(setq pt (getpoint "\nPick a pt for block "))
(command "-insert" "SampleBlock" pt 1 1 0)
(setq obj (vlax-ename->vla-object (entlast)))
;(setq val (LM:getdynpropallowedvalues blk prp ))
(setq vals (LM:getdynpropallowedvalues obj "Name" ))
(setq vals (cons "please choose" vals))
(if (not AH:Butts)(load "Multi Radio buttons.lsp"))
(if (not AHbut)(setq AHbut 1))
(setq ans (ah:butts 1 "v" vals))
(LM:setdynpropvalue obj "Name" ans)
(princ)
)

example

SeaHaven_0-1662086888634.png

 

 

 

 

0 Likes
Message 10 of 11

ronjonp
Mentor
Mentor

@timothy_crouse wrote:

The lisp works on the blocks now.

 

Thank You for your help

-Tim C.


Glad to help. 👍

0 Likes
Message 11 of 11

tdivittis
Advocate
Advocate

Awesome, simple piece of code.  Thanks for posting this.  😉

 

I'm very rusty with lisp, to say the least.  This post likely saved me several hours.

0 Likes