Thank LeeMac
I crudely modified to allow for:
- increment selection
- prefix & suffix
- (defun c:AttNum (/ *error* MakeVariant Itemp MakeSelectionSet DOC OBJ OBJECTLIST SS TAG UFLAG ) (vl-load-com) ;; Lee Mac ~ 15.04.10 (setq tag "SM_TAG") (defun *error* (msg) (if uFlag (vla-EndUndoMark(vla-get-ActiveDocument (vlax-get-acad-object)) ) ) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")(princ (strcat "\n** Error: " msg " **")) ) (princ) ) (defun MakeVariant (data datatype) (vlax-make-variant (vlax-safearray-fill(vlax-make-safearray (eval datatype) (cons 1 (length data)))data ) ) ) (defun Itemp (collection item / result) (if (not (vl-catch-all-error-p (setq result (vl-catch-all-apply (function vla-item) (list collection item) ) ) )) result ) ) (defun MakeSelectionSet (ref / SelSets SelSet) (if (setq SelSet (itemp (setq SelSets (vla-get-SelectionSets (vla-get-ActiveDocument (vlax-get-acad-object) ) ) ) ref )) (vla-delete SelSet) ) (vla-add SelSets ref) ) (setq *start (cond (*start) (1) ) );;; (setq *start;;; (1-;;; (cond;;; ( (getint;;; (strcat "\nSpecify Starting Number : ";;; );;; );;; );;; (*start);;; );;; );;; ) (setq startnum (cond (startnum) (1) ) ) (setq startnum (cond ((getint (strcat "\nSpecify Starting Number : " ) ) ) (startnum) ) ) (setq INC (getint (strcat "\nSpecify Increment " ) ) ) (setq *start (- startnum INC)) ; lm var set (setq prefix (getstring (strcat "\nSpecify Prefix" ) ) ) (setq sufix (getstring (strcat "\nSpecify Sufix" ) ) ) ; rc (if (zerop(vla-get-Count (setq ss (vla-get-PickFirstSelectionSet (setq doc (vla-get-ActiveDocument (vlax-get-acad-object) ) ) ) )) ) (progn (setq ss (MakeSelectionSet "Tree_SS")) (vla-SelectOnScreenss(MakeVariant '(0 66) vlax-vbInteger)(MakeVariant '("INSERT" 1) vlax-vbVariant) ) ) ) (if (not(zerop (vla-get-Count ss)) ) (progn (setq UFlag (not (vla-StartUndoMark doc) ) ) (vlax-for obj ss(setq ObjectList (cons (cons obj (vlax-safearray->list (vlax-variant-value (vlax-get-property obj 'InsertionPoint) ) ) ) ObjectList )) ) (vla-delete ss) (mapcar(function (lambda (block) (mapcar (function (lambda (attribute) (if (eq tag (vla-get-TagString attribute)) (vl-catch-all-apply (function vla-put-TextString) (list attribute (strcat prefix (itoa (setq *start (+ INC *start))) sufix ) ) ;rc ) ) ) ) (vlax-invoke block 'GetAttributes) ) ))(mapcar (function car) (vl-sort ObjectList (function (lambda (point1 point2) (< (caddr point1) (caddr point2)) ) ) )) ) (setq UFlag (vla-EndUndoMark doc) ) ) ) (princ))
|