mostafa badran Posted September 2, 2020 Posted September 2, 2020 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) ) Quote
rog1n Posted September 2, 2020 Posted September 2, 2020 (edited) (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 September 2, 2020 by rog1n Quote
rlx Posted September 2, 2020 Posted September 2, 2020 or (vla-put-textstring (cdr n) (if (< i 10) (strcat "0" (itoa i))(itoa i))) 1 Quote
mostafa badran Posted September 2, 2020 Author Posted September 2, 2020 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. Quote
rlx Posted September 2, 2020 Posted September 2, 2020 you're welcome mostafa , for what its worth , solution provided by rog1n is just as good Quote
mostafa badran Posted September 3, 2020 Author Posted September 3, 2020 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. Quote
Recommended Posts
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.