@jclaidler wrote:
Basically, I just need a 'count' of how many blocks have 'nested blocks'.
---[and]---
.... What my user needs is just a total 'count' of the nested blocks. ....
Those descriptions seem like different things to me. For the first one [while it seems curious to me that such a number would be of any use without also determining which Blocks they are, because presumably you want to do something with the information], you could take this thing I did a few years ago:
;; BlockNestList.lsp [command name: BNL]
;; Returns a list of lists of all Block and Xref names and all other Blocks/
;; Xrefs/Minserts nested within each. [Will also list Windows Metafiles
;; as if nested Blocks, because they are also "Insert" objects, but filters out
;; old-style Hatch pattern and Dimension "blocks."]
;; Each sub-list consists of the parent Block name followed by any Block(s)
;; nested in its definition. Does not contain names of Blocks nested more
;; than one level down -- see the sub-list for each nested Block's name.
;; Does not include Blocks containing no nested Blocks in overall list [see
;; note below to have them included].
;; Kent Cooper, May 2011
(defun C:BNL (/ blk blknamelist blklist blkitem)
(setq blknestlist nil)
; clear list if used more than once; not localized in case User
; wants to make use of overall list after routine is finished
(while ; list of all names in Block table
(setq blk (cdadr (tblnext "block" (not blk))))
(if (not (wcmatch blk "`*D*,`*X*"))
; not Dimension or old-style Hatch pattern "block" -- use
; string "`*D*,`*X*,`*U*" to also ignore anonymous Blocks
(setq blknamelist (cons blk blknamelist)); add name to list
); end if
); end while
(foreach blk blknamelist
(setq
blklist nil blklist (list blk); start sub-list over for subject Block name
blkitem (tblobjname "block" blk); parent Block entity name
); end setq
(while (setq blkitem (entnext blkitem)); looks at Block's contents; nil at end
(if
(and
(= (cdr (assoc 0 (entget blkitem))) "INSERT")
(not (wcmatch (cdr (assoc 2 (entget blkitem))) "`*D*,`*X*"))
; not Dimension or old-style Hatch pattern "block" -- use
; string "`*D*,`*X*,`*U*" to also ignore anonymous Blocks
(not (member (cdr (assoc 2 (entget blkitem))) blklist)); not already in sub-list
); end and
(setq blklist (append blklist (list (cdr (assoc 2 (entget blkitem))))))
;; add any Insert object's name to subject Blocks' sub-list
); end if
); end while -- contents of current subject block
(if (> (length blklist) 1)
; ignore sub-lists of only one item [Blocks w/o nested Insert objects]. To
; include them, remove or comment out (if... line above and ); end if
; line below. Such Block names will appear alone in one-item sub-lists.
(setq blknestlist (cons blklist blknestlist)); add sub-list to overall list
); end if
); end foreach
blknestlist
); end defun
(prompt "\nType BNL to make a Block Nesting List.")
and just replace this line just before the end:
blknestlist
with this instead:
(length blknestlist)
[and change the prompt at the bottom]. That will give you just a raw integer -- the number of Block definitions which contain any Block(s) nested within them. [And if that's really all you need, of course it could be simplified considerably. But without simplification, it does provide the availability of 'blknestlist' so if you need to, you can check out which Blocks have nested Blocks in them, and what those nested Blocks are.]
For the second description, "a total 'count' of the nested blocks" raises some of the same questions as in my first reply, and maybe some other similar ones.
Kent Cooper, AIA