Jump to content

Att block renumbering


mostafa badran

Recommended Posts

Hi,all
I'm stuck in this lisp the result give 3 digit how can i resolve it to work with 2 digit see attached file.
any help appreciated.

(defun c:natt(/ snum enum ip ats blist)
  (setq snum 1)
  (if (setq ssBlks(ssget '((0 . "insert") (66 . 1))))
    (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 enum (sslength ssBlks))
      (setq i snum)
      (foreach n blist
	(vla-put-textstring (cdr n) (strcat "0" (itoa i)))
	(setq i (1+ i))
	(if (> i enum)
	  (setq i snum)
	)
      )
    )
  )
  (princ)
)

 

2020-09-02_20-00-47.png

Link to comment
Share on other sites

(defun c:natt(/ snum enum ip ats blist)
  (setq snum 1)
  (if (setq ssBlks(ssget '((0 . "insert") (66 . 1))))
    (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 enum (sslength ssBlks))
      (setq i snum)
      (foreach n blist
	;(vla-put-textstring (cdr n) (strcat "0" (itoa i)))
        (vla-put-textstring (cdr n) (ApplyZeros (itoa i) 2))
	(setq i (1+ i))
	(if (> i enum)
	  (setq i snum)
	)
      )
    )
  )
  (princ)
)



;from https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/copy-first-layout-multiple-times-and-number-incrementally/td-p/7030955
(defun ApplyZeros (StrInt NDigit)
 (if (< (strlen StrInt) NDigit)
  (repeat (- NDigit (strlen StrInt))(setq StrInt (strcat "0" StrInt)))
 );c.if
 StrInt
)

 

Edited by rog1n
Link to comment
Share on other sites

2 hours ago, rlx said:

or


(vla-put-textstring (cdr n) (if (< i 10) (strcat "0" (itoa i))(itoa i)))

I appreciate your help thank you so much rx.

 

Link to comment
Share on other sites

2 hours ago, rlx said:

you're welcome mostafa , for what its worth , solution provided by rog1n is just as good

Oops sorry, 🤭I inadvertently didn't mean that, but it really is a good solution💪 thanks rog1n. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...