kratki spoj Posted February 14, 2014 Posted February 14, 2014 Hi, I'm wondering if there's a lisp that could increment numbers in selected text. For example : 1/1,1/2,1/3...to 1/2,1/3,1/4... So, program should select text and then increment or decrement prefix or sufix. Any help is appreciated. Quote
BIGAL Posted February 15, 2014 Posted February 15, 2014 Just a solution take the text read each character till you find the "/" then read the rest use rtos to make back into a number add 1 the convert to a string and add start start string. As a start search for a lisp "find character" the most common is for CSV. Quote
kratki spoj Posted February 17, 2014 Author Posted February 17, 2014 Thank's for replies. @ Lee Mac Text increment selects one element at a time. That takes time if you have numbers from one to a hundred or so. Is there a way to select al of the elements at once ? Quote
Lee Mac Posted February 17, 2014 Posted February 17, 2014 (edited) kratki spoj said: Text increment selects one element at a time. That takes time if you have numbers from one to a hundred or so. Is there a way to select al of the elements at once ? Try this quick mod: ;; Text Increment - Lee Mac ;; Increments numerical data found in a selection of Text or MText ;; objects by a value specified by the user. (defun c:txtinc ( / e i l s x ) (if (null *inc*) (setq *inc* 1.0) ) (if (setq i (getreal (strcat "\nSpecify Increment <" (rtos *inc* 2) ">: "))) (setq *inc* i) ) (if (equal 0.0 (rem *inc* 1) 1e-8) (setq *inc* (fix *inc*)) ) (if (setq s (ssget "_:L" '((0 . "TEXT,MTEXT") (1 . "*#*")))) (repeat (setq i (sslength s)) (setq e (entget (ssname s (setq i (1- i)))) x (assoc 1 e) ) (entmod (subst (cons 1 (apply 'strcat (mapcar (function (lambda ( x ) (if (and (= 'int (type x)) (= 'int (type *inc*))) (itoa (+ x *inc*)) (if (member (type x) '(int real)) (rtos (+ x *inc*) 2) x ) ) ) ) (LM:splitstring (cdr x)) ) ) ) x e ) ) ) ) (princ) ) ;; Split String - Lee Mac ;; Splits a string into a list of text and numbers (defun LM:splitstring ( s ) ( (lambda ( l ) (read (strcat "(" (vl-list->string (apply 'append (mapcar (function (lambda ( a b c ) (cond ( (= 92 b) (list 32 34 92 b 34 32) ) ( (or (< 47 b 58) (and (= 45 b) (< 47 c 58) (not (< 47 a 58))) (and (= 46 b) (< 47 a 58) (< 47 c 58)) ) (list b) ) ( (list 32 34 b 34 32)) ) ) ) (cons nil l) l (append (cdr l) (list nil)) ) ) ) ")" ) ) ) (vl-string->list s) ) ) (princ) Edited December 19, 2018 by Lee Mac Quote
kratki spoj Posted February 18, 2014 Author Posted February 18, 2014 Thank's Lee. That's what I was looking for. Quote
bababarghi Posted February 22, 2014 Posted February 22, 2014 Not sure if it may contribute to solution or not. Following trick is highly dependant to your case: I usually delete all text entities which I need to increment the numercial part of them. Copy a single pattern to proper location and then leverage the 'Find&Replace' option of AutoNumber (ExpressTools). In above scenario, you just need to copy '1/x' to all desired place. In find&replace, type 'x'. As I said, it might not be always feasible to everyone but I use it a lot. Hi,I'm wondering if there's a lisp that could increment numbers in selected text. For example : 1/1,1/2,1/3...to 1/2,1/3,1/4... So, program should select text and then increment or decrement prefix or sufix. Any help is appreciated. 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.