Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Attribute Sequential Numbering Lisp

8 REPLIES 8
Reply
Message 1 of 9
mperez
5637 Views, 8 Replies

Attribute Sequential Numbering Lisp

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.

Numbers.jpg

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

 

8 REPLIES 8
Message 2 of 9
dbroad
in reply to: mperez

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)
	)      )    )  ))
Architect, Registered NC, VA, SC, & GA.
Message 3 of 9
ctanto333
in reply to: dbroad

Can you please modify my lisp file for my required numbering style 

Message 4 of 9
Anonymous
in reply to: ctanto333

@ctanto333

That would not solve? http://www.lee-mac.com/numinc.html

 

 

 

Message 5 of 9
ctanto333
in reply to: Anonymous

thank you 

this will solve my problem but i need the tcount method that will save lot of time

Message 6 of 9
Anonymous
in reply to: ctanto333

@ctanto333 What do you mean with tcount method ? 

Was it multiple selection?

 

 

 

Message 7 of 9
Anonymous
in reply to: ctanto333

@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)
)

 

 

Message 8 of 9
ctanto333
in reply to: Anonymous

Sorry the text selection is not working moreover i need the text to be modified like R1 Y1 B1 R2 Y2 B2

Message 9 of 9
Sea-Haven
in reply to: ctanto333

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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost