A difficult one, two essential ways to approach it:
1) (My preferred choice)
Filter for the block name AND all anonymous blocks:
- (ssget "_X" '((0 . "INSERT") (2 . "`*U*,TITLEBLOCK") (66 . 1)))
Then use a conditional when iterating through the set to check the EffectiveName before operating on the block.
2) Use the Block Refs of the Block Definition Record:
- ;; Returns list of the Anonymous names taken by a Dynamic Block (if any) - Lee Mac 2011 - www.lee-mac.com;; Arguments: block - name of Dynamic Block.(defun AnonymousInstancesof ( block / def rec nme ref lst ) (while (setq def (tblnext "BLOCK" (null def))) (if (= 1 (logand 1 (cdr (assoc 70 def)))) (progn (setq rec (entget (cdr (assoc 330 (entget (tblobjname "BLOCK" (setq nme (cdr (assoc 2 def)))) ) ) ) ) ) (while (setq ref (assoc 331 rec)) (if (and (eq block (vla-get-effectivename (vlax-ename->vla-object (cdr ref)))) (not (member nme lst)) ) (setq lst (cons nme lst)) ) (setq rec (cdr (member (assoc 331 rec) rec))) ) ) ) ) (reverse lst))
Then use something like (similar to here):
- (defun LM:BlockList->Str ( lst del / f ) ;; © Lee Mac 2011 (defun f ( s ) (if (wcmatch s "`**") (strcat "`" s) s)) (if (cdr lst) (strcat (f (car lst)) del (LM:BlockList->Str (cdr lst) del)) (f (car lst)) ))
To create the ssget filter:
- (ssget "_X" (list (cons 0 "INSERT") (cons 2 (LM:BlockList->Str (cons "TITLEBLOCK" (AnonymousInstancesof "TITLEBLOCK")) ",")) (cons 66 1) ))
But its really 6 of one, half a dozen of the other... in the first method we are iterating through all anonymous block references in the drawing and choosing those we like; in the second we iterate through the anonymous block definitions (instead of references) and choose those we like...
Not quite, the While is redundant since the test condition will not be evaluated until the entire selection set is iterated, by which point the attributes are likely found already, and if they aren't the code will run needlessly another 3 times...
But still you're on the right track using the COND to allow you to update the information in one pass.
Perhaps take a look at my earlier code.
Lee |