Cant get correct total block count

Cant get correct total block count

johnw
Collaborator Collaborator
1,441 Views
15 Replies
Message 1 of 16

Cant get correct total block count

johnw
Collaborator
Collaborator

The routine attached counts the quantity of a specific block name, and lists the total. If there are duplicate blocks overlaying each other, it lists the overlapping amount as well. The problem is the CURRENT block total doesn't count the overlapping blocks. So if there are 6 blocks and there is 1 block overlapping one of the 6, the routine displays something line "There are 6 total blocks" "There is 1 overlapping block". There are actually 7 total blocks...

 

It should say "There are 7 total blocks" "There is 1 block overlapping". I'm not quite sure how to revise the routine to fix this. Any help would be appreciated.

0 Likes
Accepted solutions (1)
1,442 Views
15 Replies
Replies (15)
Message 2 of 16

Kent1Cooper
Consultant
Consultant
Accepted solution

Probably the simplest way:

 

(alert (strcat "Total 'fillcell' blocks in selection: " (itoa (+ count duplicateCount))
"\nDuplicate 'fillcell' blocks (by insertion point): " (itoa duplicateCount)))

 

A more involved fix would keep the running total in 'count' in a different way -- add 1 for every such Block, not just for those that don't duplicate another, but still add to the duplicate count for those that do.

Kent Cooper, AIA
Message 3 of 16

johnw
Collaborator
Collaborator

Thanks Kent. That was simple enough. 😊

0 Likes
Message 4 of 16

hippe013
Advisor
Advisor

It appears I was five minutes too late. 😆 Here is my answer. 

 

;command lets you window around linework and find all the 'filledcell' blocks and displays how many there are, and if any are overlapping.
;FCCD - Filled Cell Count & Duplicates
(defun c:FCCD (/ ss n i ename blockName insertPoint positions duplicateCount)
  (setq ss (ssget)) ; Prompt user to make a selection
  (if ss
    (progn
      (setq n (sslength ss)) ; Get number of entities in selection
      (setq i 0) ; Initialize counter
      (setq count 0) ; Initialize "fillcell" block count
      (setq duplicateCount 0) ; Initialize duplicate block count
      (setq positions '()) ; Initialize list to store insertion points

      (while (< i n) ; Loop through all entities
        (setq ename (ssname ss i)) ; Get entity name
        (setq blockName (cdr (assoc 2 (entget ename)))) ; Get block name
        (if (= (cdr (assoc 0 (entget ename))) "INSERT") ; Check if entity is a block
          (if (= (strcase blockName) "FILLCELL") ; Check if block name is "fillcell" (case insensitive)
            (progn
              (setq insertPoint (cdr (assoc 10 (entget ename)))) ; Get insertion point of the block
              (if (not (member insertPoint positions)) ; Check if insertion point is not in list
                (progn
                  (setq positions (cons insertPoint positions)) ; Add new insertion point to list
                  (setq count (1+ count)) ; Increment "fillcell" block count
                )
		(progn
                  (setq duplicateCount (1+ duplicateCount)) ; Increment duplicate count
		  (setq count (1+ count)) ; Increment "fillcell" block count
		)
              )
            )
          )
        )
        (setq i (1+ i)) ; Increment counter
      )
      ; Display results
      (alert (strcat "Total 'fillcell' blocks in selection: " (itoa count)
             "\nDuplicate 'fillcell' blocks (by insertion point): " (itoa duplicateCount)))
    )
    (alert "No selection made. Please select objects.") ; No selection made
  )
  (princ) ; Clean exit
)

 

Message 5 of 16

Kent1Cooper
Consultant
Consultant

@hippe013 's suggestion adds 1 to the 'count' variable in both cases, that is, spells that out twice.  That shouldn't be necessary.  For the more involved fix I hinted at, I'd replace this part in your original:

 

              (if (not (member insertPoint positions)) ; Check if insertion point is not in list
                (progn
                  (setq positions (cons insertPoint positions)) ; Add new insertion point to list
                  (setq count (1+ count)) ; Increment "fillcell" block count
                )
                (setq duplicateCount (1+ duplicateCount)) ; Increment duplicate count
              )

 

with this, to add it to 'count' regardless [spelled out only once], and to 'duplicateCount' only when appropriate, and add the insertion point to 'positions' only if it's not there already:

 

              (setq count (1+ count)) ; Increment "fillcell" block count
              (if (member insertPoint positions) ; Check if insertion point is in list
                (setq duplicateCount (1+ duplicateCount)) ; then -- Increment duplicate count
                (setq positions (cons insertPoint positions)) ; else -- Add new insertion point to list
              )

 

AND then go back to the original (alert) format, without adding the two values together.

 

 

Kent Cooper, AIA
Message 6 of 16

johnw
Collaborator
Collaborator

Kent, how can this routine be revised to check for filled cell count (and duplicates) when these blocks are sometimes 'nested' in a larger block. E.g. Half of a floor plan that has filled cells shown in a block, the front half of the floor plan is not a block. If I window the entire plan I would need to get a "filled cell" count from the floor plan block as well as the front half (the front half is already covered in this routine). Its the nested blocks/nested duplicate blocks that are the issue.

0 Likes
Message 7 of 16

Kent1Cooper
Consultant
Consultant

@johnw wrote:

Kent, how can this routine be revised to check for filled cell count (and duplicates) when these blocks are sometimes 'nested' in a larger block. ....


I expect the only way to do that would be to step through the entire Block table, and for every Block definition, step through its pieces to see whether any of them are that Block, and how many there are, then back at top level, find all insertions of Blocks that turned out to have those nested in them, and multiply the number of each kind by the number of such Blocks nested in it.  Probably possible, but a lot of work.  Would there ever by any nested more than one level down?

Kent Cooper, AIA
0 Likes
Message 8 of 16

komondormrex
Mentor
Mentor

another list-wise routine. duplicates numbers are comma listed.

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

(defun parse_list (_list / unique_list is_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 is_member (assoc _member unique_list))
				(setq unique_list (subst (cons (car is_member) (1+ (cdr is_member))) is_member unique_list))
		)
	)
)

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

(defun c:ffcd (/ insert_sset insertion_point_list duplicates)
	(if (setq insert_sset (ssget '((0 . "insert") (2 . "fillcell"))))
		(setq insertion_point_list (mapcar '(lambda (insert) (vlax-get insert 'insertionpoint))
								   		(mapcar 'vlax-ename->vla-object 
												(vl-remove-if 'listp (mapcar 'cadr (ssnamex insert_sset)))
										)
								   )
			  insertion_point_list (parse_list insertion_point_list) 
		)
	)
	(alert (strcat "Total 'fillcell' blocks in selection: " (itoa (apply '+ (mapcar 'cdr insertion_point_list))) 
             	   "\nDuplicate 'fillcell' blocks (by insertion point): " 
				   (if (= "" (setq duplicates (apply 'strcat 
						  							 (cdr  (apply 'append (mapcar '(lambda (insertion_point) 
						  																  	(if (< 1 (cdr insertion_point)) 
						  																  		(list "," (itoa (cdr insertion_point))) 
						  																  		(list "")
						  																  	)
						  													    	)
						  													    	insertion_point_list
						  											   	   )
						  									)
						  							 )
											  )
							 )  
					   ) "0" duplicates
				   )
    	   )
	)
	(princ)
)

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

 

0 Likes
Message 9 of 16

johnw
Collaborator
Collaborator

Kent, the blocks could be nested more than 1 level down... Don't worry about it if its a lot of work. We can work around it... Thanks for you input. 

0 Likes
Message 10 of 16

johnw
Collaborator
Collaborator

Kent, How can I have it count 3 different block names: FILLCELL, FC2, FC3

 

I currently have it counting the FILLCELL block, but need it to count the FC2 and FC3 block names... and check for duplicates of those other two as well.

 

Also, the names could be in upper or lower case.

 

Thanks for your help in advance...

0 Likes
Message 11 of 16

Kent1Cooper
Consultant
Consultant

@johnw wrote:

....

I currently have it counting the FILLCELL block, but need it to count the FC2 and FC3 block names... and check for duplicates of those other two as well.

....


Separately?  Or one collective count of all three types?  And if a Block of one name is at the same location as a Block of another name, does that count as a duplicate?

Kent Cooper, AIA
0 Likes
Message 12 of 16

johnw
Collaborator
Collaborator

One collective count of all 3 types. Yes if any of these three blocks are over the top of another then they would be counted as duplicates as well. Thanks.

0 Likes
Message 13 of 16

johnw
Collaborator
Collaborator

@Kent1Cooper Sorry Kent, if you don't mind could you show counts based on block name and then have a total:

 

Fillcell  20

FC2       10

FC3        5

 

Total Filled Cell Count 35

 

Word as you see fit... 


Thanks. Sorry about the delayed response...

0 Likes
Message 14 of 16

Kent1Cooper
Consultant
Consultant

[ See the last question in Message 11. ]

Kent Cooper, AIA
0 Likes
Message 15 of 16

johnw
Collaborator
Collaborator

Currently the program searches for a block name and if the insertion points are the same (meaning it's a duplicate). That works but is not fool-proof since the filled cell symbol is a 'filled square' centered in between an 8" wall. So the filled cell graphics could be overlapping but have one of the blocks rotated 90, 180, or 270 and the insertion points would not overlay, and therefore report "0" overlapping blocks. I don't know how to get around that and currently not worried about it right now. I hope this answers your question. If not, please advise.

0 Likes
Message 16 of 16

johnw
Collaborator
Collaborator

To continue with my last post...the filled cell insertion point is not 'centered' in the middle of the 4" square. It's located 4,4 units away from middle(center). We use the 8" wall line as the insertion point. I've attached the symbols.

0 Likes