Making a table from dynamic blocks in a drawing, referencing visibility state and one particular attribute

Making a table from dynamic blocks in a drawing, referencing visibility state and one particular attribute

wsonnek
Contributor Contributor
3,061 Views
58 Replies
Message 1 of 59

Making a table from dynamic blocks in a drawing, referencing visibility state and one particular attribute

wsonnek
Contributor
Contributor

I'm working on yet another lisp (y'all got me hooked, I swear) that's attempting to take all the blocks in a drawing and make a table with them. I started with the two lisps linked below - the first one was almost exactly what I wanted for a table, but didn't handle the dynamic blocks well. The second counted dynamic blocks, but didn't have a way to make a good table. I tried to combine them and kinda wrecked it. Either way, neither of them allowed for counting based on the SIZE attribute, which is kind of important.

 

Basically, I have a ton of different 2D valves in a drawing. The valves are dynamic so I can switch between types (ball, globe, gate, etc) in-place without messing with the size. The size is an attribute (2", 3", 1/2", etc) for the block. There are a few stand-alone valves that I also need to count. I want the table to be "Block Name" "Block Type" (that's the visibility state) "Block Size" (attribute). That way I can quickly tally up what I've got in the drawing  and figure out how many 2" ball valves I need, 3" butterfly valves, etc.

 

Thoughts?

 

https://www.lee-mac.com/dynamicblockcounter.html

https://www.lee-mac.com/blockcounter.html

 

0 Likes
Accepted solutions (1)
3,062 Views
58 Replies
Replies (58)
Message 2 of 59

cadffm
Consultant
Consultant

Hi,

 

just a question: You know about the COUNT feature?

 

Sebastian

0 Likes
Message 3 of 59

wsonnek
Contributor
Contributor

I'm sure I've tried to use it...poorly...

 

I'm okay at cannibalizing/editing existing lisps. I'm not great at starting from scratch. I only know enough to be dangerous.

0 Likes
Message 4 of 59

cadffm
Consultant
Consultant

>"I only know enough to be dangerous"

 

Made my day. I had the same state for years (ago) 🤣

Sebastian

0 Likes
Message 5 of 59

paullimapa
Mentor
Mentor

Doesn't the standard DATAEXTRACTION command give you this?

paullimapa_0-1739994662917.png

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 6 of 59

wsonnek
Contributor
Contributor

Kinda. The problem with that is that I have to sort through and uncheck 800 attributes to get to the ones I want. It's not ideal. Plus the 8 levels of setup - would like something that just runs. Maybe I could make a lisp that uses that command but: auto-saves to the current working folder with the name of the drawing and auto-checks the boxes I want? Is that possible?

0 Likes
Message 7 of 59

cadffm
Consultant
Consultant

Hi,

 

>I have to sort through and uncheck 800 attributes to get to the ones I want.

You can uncheck all with two clicks, check the ones you need.

 

>Is that possible?

No

 

 

Sebastian

0 Likes
Message 8 of 59

wsonnek
Contributor
Contributor

Back to the lisp drawing board, I guess. Thank you.

0 Likes
Message 9 of 59

Sea-Haven
Mentor
Mentor

You can make a list of a block, with effective name then say its attributes, you can sort and count the list. That is where I would start. You may be able to setup a look up table for the attributes depending on a blocks name. Valv22 use 3, 4 & 7. Use ( setq atts  (vlax-get blk 'attributes)) so you would make a list of block name, then textstring of   (nth 3 atts), textstring (nth 4 atts) and so on.

 

Do you know about using  (vlax-get blk 'attributes) ?

 

I may have a shortcut to write which atts to use pick a blk and a dcl is displayed using toggles to choose which attributes, would say write a list that could be saved into other code.

0 Likes
Message 10 of 59

wsonnek
Contributor
Contributor

I understood about half of that? I do not know about using (vlax-get blk 'attributes) but I'll look into it. I was kind of hoping to splice the two lisps I referenced in my OG post together, as they each individually do part of what I want - I just keep breaking it when I try to put them together.

0 Likes
Message 11 of 59

komondormrex
Mentor
Mentor

@wsonnek 

what exactly are the names for visibility states and attribute tags for 'block size'. i presume the latter is just "SIZE". are they invariable throughout all dynamic valve blocks?

0 Likes
Message 12 of 59

wsonnek
Contributor
Contributor

I have probably 20+ visibility states for the dynamic valve blocks; however, the attribute tag I'm most concerned with is the SIZE one (called SIZE). It's the same on the non-dynamic blocks as well. I can always add tags if needed. I hope.

0 Likes
Message 13 of 59

komondormrex
Mentor
Mentor

no no no, i do not mean visibility states, it is visibility name. you can see it in property pallette under custom title right on the left. 

0 Likes
Message 14 of 59

Sea-Haven
Mentor
Mentor

Ok if you get a copy of Lee-mac dynamic block lisp then this is the function you want to use to get current visibility.

 

;; Get Dynamic Block Visibility State  -  Lee Mac
;; Returns the value of the Visibility Parameter of a Dynamic Block (if present)
;; blk - [vla] VLA Dynamic Block Reference object
;; Returns: [str] Value of Visibility Parameter, else nil

(defun LM:getvisibilitystate ( blk / vis )
    (if (setq vis (LM:getvisibilityparametername obj))
        (LM:getdynpropvalue obj vis)
    )
)

 You will need a couple of other defuns as well. LM:getvisibilitystate, LM:getvisibilityparametername.

 

As you want only the "SIZE" attribute that should be a easy next step. No dwg to test code on.

0 Likes
Message 15 of 59

komondormrex
Mentor
Mentor

could've been done easier/shorter if there is the only visibility name eg. "Type".

0 Likes
Message 16 of 59

wsonnek
Contributor
Contributor

The Lee-Mac does return visibility name already, but it doesn't make a table as far as I can tell. It also doesn't include attribute properties.

0 Likes
Message 17 of 59

wsonnek
Contributor
Contributor

I think the visibility name is just "Visibility1." I was actually unaware you could change that.

0 Likes
Message 18 of 59

wsonnek
Contributor
Contributor

Ah. I think it's just "Visibility1." I didn't know that could be changed actually. Learn something new every day!

0 Likes
Message 19 of 59

Sea-Haven
Mentor
Mentor

You are correct no complete code without a sample dwg to test on hard to see what can go wrong.

0 Likes
Message 20 of 59

komondormrex
Mentor
Mentor

just for starting off. the get_the_valves custom command will output in the console all valves parsed by similar listed properties in the form of dotted pairs, where the cdr of each dotted pair will have a total count of the same properties' valves. 

 

;******************************************************************************************************************************************************************************

(defun parse_list (_list / unique_list old_member)
	(foreach _member _list (if (not (member _member unique_list)) (setq unique_list (append unique_list (list _member)))))
	(setq unique_list (mapcar '(lambda (_member) (cons _member 0)) unique_list))
	(foreach _member _list
		(if (setq old_member (assoc _member unique_list))
				(setq unique_list (subst (cons (car old_member) (1+ (cdr old_member))) old_member unique_list))
		)
	)
)

;******************************************************************************************************************************************************************************

(defun c:get_the_valves (/ insert_sset valve_list size_attribute vis_property)
  (if (setq insert_sset (ssget "_x" '((0 . "insert") (66 . 1))))  ;selects all attibuted inserts
    (progn
	(setq valve_list (parse_list
			   (vl-remove nil
		       		(mapcar '(lambda (insert) (if (and (vl-some '(lambda (attribute) (= "SIZE" (vla-get-tagstring (setq size_attribute attribute)))) 
			                  			    	     (vlax-invoke insert 'getattributes)
			              			           )
								   ;checks if there is "SIZE" tagged attribute in insert
				                                   (vl-some '(lambda (dyn_property) (= "Visibility1" (vla-get-propertyname (setq vis_property dyn_property))))
								    	     (vlax-invoke insert 'getdynamicblockproperties)
							           )
								   ;checks if there is "Visibility1" dynamic property in insert
		                           	      	      )
						      	      (list (vla-get-effectivename insert) (vlax-get vis_property 'value) (vla-get-textstring size_attribute)) 
		                  	          	  )
				     	 )
			  	     	 (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex insert_sset))))
			    	)
	             	   )
		         )
	)
      	(foreach valve valve_list (print valve))
    )
  )
  (princ)
)

;*****************************************************************************************************************************************************************************

 

 

 

 

0 Likes