Request to create LISP routine for block counting

Request to create LISP routine for block counting

akhtar4223
Enthusiast Enthusiast
4,921 Views
6 Replies
Message 1 of 7

Request to create LISP routine for block counting

akhtar4223
Enthusiast
Enthusiast

Hi,

I have a drawing which contains various specific blocks. Each block has unique name and layer. Currently if i want to count the total quantity based in type, i use select similar command and than enter the quantity in table shown on model space. I have around 10-15 different types of blocks in model space. Counting them every time from model space and showing in layout space makes in time consuming.

I request to create a LISP routine based on block name that can count the number of blocks and show the same on "Total quantity" column of legend table shown in attached file.

Light_Fixture_Table.JPG

Regards

0 Likes
Accepted solutions (1)
4,922 Views
6 Replies
Replies (6)
Message 2 of 7

andkal
Collaborator
Collaborator

You can try this program if it suits your needs :
https://autolisps.blogspot.com/p/filterselectionby.html 
It can filter selection by blocks and it shows also the quantity of each item in the list.
The numbers in the table you would have to type manually


• www.autolisps.blogspot.com - Productivity plugins for Autocad and Autocad MEP
• Autodesk AppStore
0 Likes
Message 3 of 7

john.uhden
Mentor
Mentor

I must say that I applaud the wordage of your request.

So many people start with, "I need..." which to me means immediately that they want freeware.

I think you do too, but your words come across as a lot less demanding and assumptive.

Might you know any AutoLisp at all?  If so we can help you to help yourself to become a more valuable person, not only for yourself but in time for others in return.  OR, it's time to start learning, and there is  a multitude of great teachers here from all over the world.

BTW, if you develop an attachment to any of us, do not send private messages unless you want our addresses to send us money (or winning lottery ticket numbers).  We all contribute for free, and your questions will gain myriad more attention in pubic than in private, which means better odds of reaching solutions.

AND than you for asking.  There may be many other lurkers who have similar questions but may be too shy to ask.  They can all benefit as well.

John F. Uhden

0 Likes
Message 4 of 7

Sea-Haven
Mentor
Mentor

Like John the "I want quantities of blocks" is a question asked many times. Did you google Block count to table ? 

 

I have a few to do with blocks but not a simple block count to table. Most I have are more customised. This is the put block in a cell example.

 

 

; Thanks to FIXO for code ideas
; block in table example by Alan H
; May 2018

(setq objtable (vlax-ename->vla-object (car (entsel "\nPick table"))))
(setq row 3 col 2)
(setq adoc (vla-get-activedocument (vlax-get-acad-object)))
(setq blkcount (vla-get-count (vla-get-blocks adoc)))
(setq i 1)
(repeat blkcount
(setq bitem (vla-item (vla-get-blocks adoc) i))
(if (= "NORTHN" (vla-get-Name bitem ))
(progn
(setq blkID (vla-get-objectid bitem))
  (vla-setblocktablerecordid objtable row col blkID :vlax-true)
  (vla-setblockscale objtable row col 0.75)
  (vla-setcellalignment objtable row col acMiddlecenter)
  (vla-setcellcontentcolor objtable row col acmcol)
  (setq i (- blkcount 1))
)
)
(princ(setq i (+ i 1)))
)

 

 

two questions, where does the description come from does it need a look up block / description, and where does type come from ?

0 Likes
Message 5 of 7

akhtar4223
Enthusiast
Enthusiast

I am using the attached LSP for this but the output of this gives table which does not satisfy my requirement. 

The problem is i don't have knowledge of LISP or VBA.

There are many ways to get count manually but i am looking for LSP routine which can count the blocks from model space and give the output in TEXT format in quantity column given on layout space of my shared file.

Sharing my base file again.

Light_Fixture_Table.JPG

0 Likes
Message 6 of 7

fkp7057
Advocate
Advocate
Accepted solution

Hello,

 

Check Below code Modified by @hak_vz.

This might be useful for you. in this lisp count block which is in model space but you have to add diesel expression in filed something like $(getenv, BLOCK_COUNT_"S1" , Replace S1 with your block name.

Thanks to @hak_vz, now, this lisp is able to count dynamic blocks which are having visibility/flip or other action.

 

 

(defun c:recount (/ block_list ss cnt i bo);
	(setq block_list
		(list 
			"S1" "S2" "S3" "S4" "S5" "S6" "S7" "S8" "S9" "S10" "S11" "S13" "S14" "S15" 
			"S16" "S17" "S18" "S19" "S20" "S21" "NORMAL PUSH BUTTON" "NORMAL PUSH BUTTON (W)" 
			"NORMAL PUSH BUTTON (FLAME PROOF)" "LDB" "ELDB" "SPDB" "ESPDB" "ESPDB" "DB" "JB"
			"MODULE_PLATE"
		)
	)
	(setq ss (ssget "X" (list (cons 0 "INSERT") (cons 410 "Model"))))
	(foreach block_name block_list
		(setq i -1 cnt 0)
		(while (< (setq i (1+ i)) (sslength ss))
			(setq bo (vlax-ename->vla-object (ssname ss i)))
			(if (= block_name (vlax-get bo 'EffectiveName)) (setq cnt (1+ cnt)))
		)
		(princ (strcat "\nBLOCK_COUNT_" block_name " " (itoa cnt)))
		(setq env_name (strcat "BLOCK_COUNT_" block_name))
		(setenv env_name (itoa cnt))
	)
	(princ "\n")
	(command "_REGEN")
	(princ)
)

 

 

above code, you just need to add your block name. it is case-sensitive. 

 

Hope this will help you.

 

Original post link :

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/block-count-and-link-with-field-text...

0 Likes
Message 7 of 7

akhtar4223
Enthusiast
Enthusiast
Thank you very much...this works as i want..
0 Likes