List of visibility states does not work with all blocks

List of visibility states does not work with all blocks

r_de_nier
Contributor Contributor
246 Views
3 Replies
Message 1 of 4

List of visibility states does not work with all blocks

r_de_nier
Contributor
Contributor

With this peace of code I want to get the visibility states in a list. It works fine with some blocks, but not with others.

The blocks looks the same to me, but I can not find out why it does not work with all blocks.

This is the code and in the attachment I have a drawing with to almost similar dynamic blocks.

One will work and the other one gives nil.

(defun c:lv (/ list_visi)

      (if (and (setq blk (car (entsel "\nSelect Dynamic block with Visibility State :")))
         (= (vla-get-isdynamicblock (setq blk (vlax-ename->vla-object blk))) :vlax-true)
    )
  (progn
    (setq props (vlax-invoke blk 'getdynamicblockproperties))
    (foreach prop (vlax-get (car props) 'allowedvalues)
      (setq list_visi (cons (list prop) list_visi))
    )
  )
)
  (setq list_visi (reverse list_visi))
)

 

247 Views
3 Replies
Replies (3)
Message 2 of 4

komondormrex
Mentor
Mentor

to get visibility states  of a visibility property you need to specify one. that is "Visibility1"  in your particular case.

 

 

(defun c:lv (/ list_visi)
	(if (and (setq blk (car (entsel "\nSelect Dynamic block with Visibility State: ")))
         	 (= (vla-get-isdynamicblock (setq blk (vlax-ename->vla-object blk))) :vlax-true)
    )
  	(if (vl-some '(lambda (dyn_property) (= "Visibility1" (vla-get-propertyname (setq vis_property dyn_property))))
				  (vlax-invoke blk 'getdynamicblockproperties)
		)
    	(vlax-get vis_property 'allowedvalues)
    )
  )
)

 

 

 

 

0 Likes
Message 3 of 4

r_de_nier
Contributor
Contributor

 Again you are my hero. How on earth could I figure this out by my self? I'm used to the non VL calls.

Slowly I get the hang of it, but most of the times I got stuck.

Thanks again!

0 Likes
Message 4 of 4

ВeekeeCZ
Consultant
Consultant

@r_de_nier wrote:
...How on earth could I figure this out by my self? I'm used to the non VL calls.

Slowly I get the hang of it, but most of the times I got stuck.

...


 

So it seems that the issue is not so much vl-functions but basic foreach.

 

(defun c:lv (/ list_allowedvalues)
  
  (if (and (setq blk (car (entsel "\nSelect Dynamic block with Visibility State :")))
	   (= (vla-get-isdynamicblock (setq blk (vlax-ename->vla-object blk))) :vlax-true)
	   )
    (foreach prop (vlax-invoke blk 'getdynamicblockproperties)
      (foreach allowedvalue (vlax-get prop 'allowedvalues)
	(setq list_allowedvalues (cons allowedvalue list_allowedvalues)))))
  list_allowedvalues
  )

 

In this case this works because no other property but the visibility has "allowedvalues" 

0 Likes