We currently use a lisp routine that was shared by Chaitanya Chikkala to renumber a block with a single attribute. Now i'm looking to expand on the lisp a little further. Looking for a routine that will sequentially number the attribute staring from left to right then top to bottom and only limit the max number to 13 or 14, which the user will input. So for example, if I have a grid of 5 x 5 blocks, the lisp would start with the upper left hand corner at number 1 then work it's way to the right. Once it reaches the number that was inputed by a user, the renumbering would start back at 1.
I've tried to peace a few lisp together but have had no success.
I've attached the lisp routine that we currently use.
Any help would be appreciated.
Thanks,
Mike
Good try. You never indicated a maximum number and seem to have a problem sorting, which can be difficult. Here is one option to learn from:
;;D. C. Broad, Jr. 1/9/2017 ;;renumber first attribute of blocks sequentially ;;from left to right and top down from snum to enum ;;repeating. No error checking. ;;Call with (renum) (defun renum (/ snum enum ip ats blist) (setq snum (getint "\nLow(start integer): ")) (setq enum (getint "\nHigh(end integer): ")) (if (ssget '((0 . "insert") (66 . 1))) ;;selection exists (progn (vlax-for n (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object) ) ) (setq ip (vlax-get n 'insertionpoint)) (setq ats (vlax-invoke n 'getattributes)) ;;make list of elements (insertion point . first attribute object) (setq blist (cons (cons ip (car ats)) blist)) ) ;;sort into rows and columns left to right and top down (setq blist (vl-sort blist '(lambda (a b) (if (equal (cadar a) (cadar b) 0.001) (< (caar a) (caar b)) (> (cadar a) (cadar b)) ) ) ) ) (setq i snum) (foreach n blist (vla-put-textstring (cdr n) (itoa i)) (setq i (1+ i)) (if (> i enum) (setq i snum) ) ) ) ))
@ctanto333 This was done a while ago in the forum to run in a block with multiple attributes, but I believe it will suit you.
Note: Replace the pink text with the TAG of your block.
(defun c:test (/ pre post i j ss1 dat ent etdata found) (if (and (/= (setq pre (getstring "\nPrefix: ")) "") (not (initget (+ 2 4))) (setq post (getint "\nSufix: ")) ) (progn (setq j 0) (while (setq ss1 (ssget '((0 . "insert") (66 . 1)))) (setq i -1) (repeat (sslength ss1) (setq i (1+ i)) (setq dat (strcat pre (itoa (+ post j))) ent (ssname ss1 i) j (1+ j) found nil) (while (and (setq ent (entnext ent)) (not found)) (setq etdata (entget ent)) (if (and (eq (cdr (assoc 0 etdata)) "ATTRIB") (eq (strcase (cdr (assoc 2 etdata))) "A1") ) (progn (entmod (subst (cons 1 dat) (assoc 1 etdata) etdata)) (entupd ent) (setq found t) ) ) ) ) ) ) ) (princ) )
The easiest way is to use the attribute order make sure your attributes have been created in the same order that you expect to number them ok you can have 20 but they must flow left to right then its simple to start at 1 get to max set back to 1 using the getattribute function and put-textstring. You can move the attribute order google this.