另一个(只是为了好玩):
- (defun GetBlkAttVals ( bnm / o L )
- (if (and (setq o (FirstBlkOccurrence bnm)) (setq L (vlax-invoke o 'GetAttributes)) )
- (mapcar 'vla-get-TextString L)
- )
- ); defun GetBlkAttVals
- ; recursive
- (defun FirstBlkOccurrence ( n / rec )
- (defun rec ( b n i / o )
- (cond
- ( (vl-catch-all-error-p (setq o (vl-catch-all-apply 'vla-item (list b i)))) (prompt "\nError") )
- ( (and (vlax-property-available-p o 'EffectiveName) (= n (vla-get-EffectiveName o))) o)
- ( (rec b n (1+ i)) )
- ); cond
- ); defun
- (rec (vla-get-Block (vla-get-ActiveLayout (vla-get-ActiveDocument (vlax-get-acad-object)))) n 0)
- ); defun FirstBlkOccurrence
- ; iterative
- (defun FirstBlkOccurrence ( n / i->L b o )
- (defun i->L ( i / L ) (if (eq 'INT (type i)) (repeat i (setq L (cons (setq i (1- i)) L)))) )
- (setq b (vla-get-Block (vla-get-ActiveLayout (vla-get-ActiveDocument (vlax-get-acad-object)))))
- (vl-some
- (function
- (lambda (x)
- (if
- (and
- (setq o (vla-item b x))
- (vlax-property-available-p o 'EffectiveName)
- (= n (vla-get-EffectiveName o))
- )
- o
- )
- )
- )
- (i->L (vla-get-Count b))
- ); vl-some
- ); defun FirstBlkOccurrence
用法示例-(其中块名区分大小写):
- (GetBlkAttVals "MyBlockName")
|