Dynamic Block count

Dynamic Block count

Anonymous
Not applicable
6,263 Views
12 Replies
Message 1 of 13

Dynamic Block count

Anonymous
Not applicable

Hi,

 

Is there a routine to block count with breakdown of different visibility.

Have tried the Dynamic Block Counter from Lee Mac but somehow not breaking down one visibility type as attached dwg.

I am using Autocad 2017, windows 7.

 

Thanks.

mcmk

 

0 Likes
Accepted solutions (1)
6,264 Views
12 Replies
Replies (12)
Message 2 of 13

ВeekeeCZ
Consultant
Consultant

How about kindly ask the author @Lee_Mac if he could look into the issue?

0 Likes
Message 3 of 13

SeeMSixty7
Advisor
Advisor

I started teaching someone on another thread, then things flaked out on responses being too slow. Take a look and if this is close to what you are looing for I can work through it some more to get you what you want.

 

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/if-visibility-state-then-quot-value-...

 

Good Luck,

0 Likes
Message 4 of 13

Anonymous
Not applicable

Yes. Lee-Mac if you see this, please help to improve your lisp to another level.

or if anyone else can, any help is most appreciated.

Thanks

0 Likes
Message 5 of 13

Lee_Mac
Advisor
Advisor

Hi,

 

Have you tried my existing Dynamic Block Counter application?

This program will allow you to count block references by visibility state.

 

Lee

Message 6 of 13

SeeMSixty7
Advisor
Advisor

I put this together for you. I did not know what you wanted to do with the actual data, so I made a crude text output to show the results.

 

As I was putting this together I see @Lee_Mac has provided a solution with pretty output. Mine, pretty, not so much. lol

 

I have some comments in there to help if you want to figure out what I was doing.

 

Here you go, good luck,

;By: Clint Moore
;Date: 05-16-2017
(defun countblocksandstates() 		;define in the new function
	(setq myss (ssget "X" '((0 . "INSERT")))) ; Create a selection set of all the inserts (blocks) in your drawing
	(if myss ;Check and see if there is a selection set 
		(progn ;group all the following commands into one process block
			(setq mynum (sslength myss) ; get the length of the selection set 
			      mycnt 0 ; set up a counter to step through
			      myblklist (list)
			)
			(while (< mycnt mynum) ;see if we have step through them all 
			    (setq blkent (ssname myss mycnt) ; retrieve the insert definition based on the index position of the counter
			          blkdata (entget blkent) ; get the DXF data of the insert entity
			          blkname (cdr (assoc 2 blkdata)) ; get the traditional block name
			          blkobj (vlax-ename->vla-object (cdr (assoc -1 blkdata))) ; get the entity object
			          blktruename (vla-get-EffectiveName blkobj); get the effective block name (dynamic block store actual name here)
			          blkvisstate (myGetDisplayStateFunction blkobj) ; Here we call our function ot get visstate
			          mycnt (1+ mycnt); bump the counter
			    ); close the setq
			    (if (assoc blktruename myblklist)
			    	(setq myblklist (subst (list blktruename (bumpBlkStateCount blkvisstate (cadr (assoc blktrueName myblklist)))) (assoc blktrueName myblklist) myblklist) )
			    	(setq myblklist (append myblklist (list (list blktruename (list (list blkvisstate 1))))))
			    )

		   ); close the while loop
	    ); close the progn
	    (princ "\nNo BLOCKS Found") ; no blocks found if the myss var is nil
	 ); close the if statement
	 (princ) ; end the command cleanly
	 myblklist
);close the defun
(defun bumpBlkStateCount (blkState blkMasterList) ; this function just bumps count by 1
	(if (assoc blkState blkMasterList)
		(setq blkStateCount (cadr (assoc blkState blkMasterList))
			  returnMasterList (subst (list blkState (1+ blkStateCount)) (assoc blkState blkMasterList) blkMasterList)
		)
		(setq returnMasterList (append blkMasterList (list (list blkState 1))))
	)
	returnMasterList
)
(defun myGetDisplayStateFunction (myBlockObject) ; function dedicated to accepting a block object and will return the vis state
   (if (= (vla-get-isdynamicblock myBlockObject) :vlax-true) ; Check and see if it is a dynamic block
		(progn ; Same as before create a process block for this conditon of the if statement
			(setq myBlockDynProps(vlax-safearray->list (vlax-variant-value (vla-getdynamicblockproperties myBlockObject))))
			; The above line digs in dyamic block properties and creates a list of them for us to cycle through
			(foreach dynprop myBlockDynProps ; For each loops through each item(property) in the list
				(setq propname (vla-get-propertyname dynprop)) ; get the name of the property
				(if (= propname "Visibility1") ; We are looking for visibility state
					(progn 
						(setq retVisstate (vlax-variant-value (vla-get-Value dynprop))) ;create a return value when we find it
					)
				)
			)
		)
		(setq retVisstate "Default") ; Not a dynamic block so no vis state
	)
	retVisstate
)
;;;the following command just displays statsu of blocks found in drawing
(defun c:blocksummary()
	(setq myblkdata (countblocksandstates))
	(princ "\nBlock List")
	(foreach blkname myblkdata
		(princ "\nBlock Name:\t")
		(princ (car blkname))
		(foreach blkstate (cadr blkname)
			(princ (strcat "\n\t->->[" (car blkstate) "]\t" (itoa (cadr blkstate))))
		)
	)
	(princ)
)
Message 7 of 13

Anonymous
Not applicable

Thanks everyone.

Lee, I have tried your DBCount but it didn't break down the different visibility of one block.

 

This block is different from the others in the way the Lookup Length is control by a stretch action. While the others are purely on/off visibility.

So, is it possible to your lisp to accomodate Lookup option as well.

 

Thanks

 

0 Likes
Message 8 of 13

Anonymous
Not applicable

SeeMSixty7, Thanks. Likewise this doesn't have a good breakdown of this block, which is a Lookup block.

Can this be change to suit?

 

Thanks

0 Likes
Message 9 of 13

SeeMSixty7
Advisor
Advisor
Accepted solution

It seems that the commands you have do the jobs they were intended to do. Your are now asking for not only the States, but also the various other settings from within the dynamic block. I would recommend taking what you have and stick with it, then add another function to break out the various other settings in the dynamic blocks. As you know there are a number of other settings to dig into on a dynamic block. If you know that you are looking for a particular setting on a dynamic block then you can create a function to provide that. You have the heart of it all in the code you have from @Lee_Mac and myself.

 

You can look at the code and see that you can easily develop a new function to examine the distance1 value of your specified block and create something like the following.

(defun getdyn-block-Distance1(dyn-block-object)
	(foreach dynprop dyn-block-object
		(setq propname (vla-get-propertyname dynprop))
		(if (= propname "Distance1")
			(setq distvalue (vlax-variant-value (vla-get-Value dynprop)))
		)
	)
	distvalue
)

To create a routine so generic that it will discover every setting and every option on a dynamic block would be a large chunk of code that would result in a very complex data structure that would be equally complex to report on. Considering you want to look at very specific parts of the data, you can write the code to report on that data alone. Hopefully that makes some sense. You have a wealth of help here on the forums to put this together, but I recommend you try putting this together for yourself. The more you dig in the more you will find you can do. Synergy!

 

On another option, depending on what you want to do with the data. The DATAEXTRACTION command will export and count your summaries for you. Run the DATAEXTRACTION command and just use the Dynamic block properties. It will export a column data set with the unique settings of all your blocks as well as counts. If you don't plan to use the values in code somewhere then data extraction works great to give you the data you want.

dataextraction.jpg

  

 

Good luck,

0 Likes
Message 10 of 13

Anonymous
Not applicable
Thanks SeeMSixty7 for reminding me Data extraction. Good choice.
Message 11 of 13

SeeMSixty7
Advisor
Advisor

You are very welcome. I'm glad to see that DataExtraction has gotten a lot better over the years. Good luck!

0 Likes
Message 12 of 13

ВeekeeCZ
Consultant
Consultant

@SeeMSixty7 wrote:

... I'm glad to see that DataExtraction has gotten a lot better over the years....


I don't use all the annual releases... but trying to keep informed of new features. I did not heard of this one... What you have in mind? When and what was something improved? I think that DE come out maybe with version 2008? ... 

0 Likes
Message 13 of 13

SeeMSixty7
Advisor
Advisor

I'm not saying DE was improved, I referring to the fact that we have DE now. Keep in mind, I've been using AutoCAD for almost 30 years, so 2008 is recent for me, GRIN!

0 Likes