9(, = 9 ( 8 )
Registered forum members do not see this ad.
Hello,
Let's say we have a group of integers as text in dwg.
How would we put them in in ascending order by one(+1) starting from a given integer?
Let me give an example to make it clear. Let's say we have the texts 1 2 5 5 5 8 9 11 11 15 and the given start integer is 6. We select them all together and the range in selection set is random. Let's say 5 2 8 15 1 5 5 11 9 11.
Now, we want to put them in ascending order by one starting from number 6 replacing the "old" range with the new. In the end we must have this:
6 7 8 8 8 9 10 11 11 12.
That is 6(in place of 1), 7(in place of 2), 8(5), 8(5), 8(5), 9(, 10(9), 11(11), 11(11), 12(15). I hope it is clear.
How would we do that in an efficient way?
Thank you in advance,
Kostas
9(, = 9 ( 8 )
Consider the following code:Example:Code:(defun renumberlist ( num lst ) (setq lst (vl-sort lst '(lambda ( a b ) (< (atoi a) (atoi b)))) num (1- num) ) (mapcar '(lambda ( a b ) (if (= a b) (itoa num) (itoa (setq num (1+ num))))) (cons nil lst) lst) )Code:_$ (renumberlist 6 '("5" "2" "8" "15" "1" "5" "5" "11" "9" "11")) ("6" "7" "8" "8" "8" "9" "10" "11" "11" "12")
Lee Mac Programming • Twitter • Exchange App Store • Dropbox (500MB free)
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Thank you Lee Mac! I will try to import your code to my routine. If I don't manage, I will come back to you. (It's very possible because your coding is in much higher level than mine). Thanks!
Thanks
You're welcome tsotzo. My code demonstrates one possible method of ordering & renumbering a set of text values, however, assuming you are looking to then modify the text content, you will need to retain the entity name of the text object during the sorting & renumbering process - I'm happy to demonstrate this if you get stuck.
Lee Mac Programming • Twitter • Exchange App Store • Dropbox (500MB free)
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Just for fun, here's a recursive function accepting a sorted list to produce the same result:Example:Code:(defun renum ( num lst ) (if lst (cons (itoa num) (renum (if (= (car lst) (cadr lst)) num (1+ num)) (cdr lst)))) )
Code:_$ (renum 6 (vl-sort '("5" "2" "8" "15" "1" "5" "5" "11" "9" "11") '(lambda ( a b ) (< (atoi a) (atoi b))))) ("6" "7" "8" "8" "8" "9" "10" "11" "11" "12")
Lee Mac Programming • Twitter • Exchange App Store • Dropbox (500MB free)
With Mathematics there is the possibility of perfect rigour, so why settle for less?
That's right!
OK, I couldn't resist
Code:(defun c:renum ( / a b i l n s x y z ) (initget 4) (setq n (1- (cond ((getint "\nSpecify starting number <1>: ")) (1)))) (if (setq s (ssget "_:L" '((0 . "TEXT") (1 . "~*[~0-9]*")))) (progn (repeat (setq i (sslength s)) (setq x (entget (ssname s (setq i (1- i)))) a (cons (assoc -1 x) a) b (cons (atoi (cdr (assoc 1 x))) b) ) ) (setq i (vl-sort-i b '<) l (mapcar '(lambda ( n ) (nth n b)) i) ) (mapcar '(lambda ( x y z ) (entmod (list (nth z a) (cons 1 (itoa (if (= x y) n (setq n (1+ n)))))))) (cons nil l) l i) ) ) (princ) )
Lee Mac Programming • Twitter • Exchange App Store • Dropbox (500MB free)
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Registered forum members do not see this ad.
& & . Lee Mac, when I first read your message I laughed with my heart and then... wow... I have no words...! You are unbelievable! You know, I had written more than double of code lines than you, and I wasn't even in the middle! What can I say... Thanks man!! You know, what's impressive is not only that you solve the problem, but the way that you do it (and the speed of course ). Thanks again!
Bookmarks