asra Posted December 22, 2019 Posted December 22, 2019 Hello, Is there a Lisp routine that can add an addition symbol to multiple text. eg. have a list all in single text 5889.12, 5685.23, etc. Results will be 5+889.12, 5+685.23, etc. Thanks, Quote
asra Posted December 22, 2019 Author Posted December 22, 2019 Error: LOAD failed: "Multi Getvals" Quote
dlanorh Posted December 22, 2019 Posted December 22, 2019 6 hours ago, asra said: Hello, Is there a Lisp routine that can add an addition symbol to multiple text. eg. have a list all in single text 5889.12, 5685.23, etc. Results will be 5+889.12, 5+685.23, etc. Thanks, What happens with 0.62 or 7.93 or 29.01 or 168.75? Quote
hanhphuc Posted December 22, 2019 Posted December 22, 2019 15 hours ago, asra said: Hello, Is there a Lisp routine that can add an addition symbol to multiple text. eg. have a list all in single text 5889.12, 5685.23, etc. Results will be 5+889.12, 5+685.23, etc. Thanks, ymg's rtosa Quote
asra Posted December 23, 2019 Author Posted December 23, 2019 HELLO All, maksud saya bukan untuk menjumlahkan angka, tapi untuk menambahkan simbol "+" 1 Quote
hanhphuc Posted December 23, 2019 Posted December 23, 2019 4 hours ago, hanhphuc said: ymg's rtosa did you click the link provided at previous post above ? 1 hour ago, asra said: HELLO All, maksud saya bukan untuk menjumlahkan angka, tapi untuk menambahkan simbol "+" ;; rtosta by ymg September 2013 ; ;; ; ;; Arguments: sta Real number to format as a Station ; ;; unit 1 for Imperials, ; ;; 2 for Metrics. ; ;; prec Integer for number of decimals ; ;; ; ;; Examples: (rtosta 0 1 0) -> "0+00" (rtosta 1328.325 1 2) -> "13+28.33" ; ;; (rtosta 0 2 0) -> "0+000" (rtosta 1328.325 2 2) -> "1+328.33" ; ;; ; ;; If sta is negative, format is as follow: ; ;; (rtosta -1328.325 1 2) -> "13-28.33" ; ;; (rtosta -1328.325 2 2) -> "1-328.33" ; ;; ; (defun rtosta (sta unit prec / str a b ) (setq str (rtos (abs sta) 2 prec)) (while (< (strlen str) (if (= prec 0) (+ unit 2) (+ prec (+ unit 3)))) (setq str (strcat "0" str)) ) (setq a (if (= prec 0) (- (strlen str) unit) (- (strlen str) prec (+ unit 1))) b (substr str 1 (- a 1)) a (substr str a) ) (strcat b (if (minusp sta) "-" "+") a) ) it does what exactly you asked 5889.12, 5685.23 (rtosta 5889.12 2 2) "5+889.12" (rtosta 5685.23 2 2) "5+685.23" Quote
BIGAL Posted December 23, 2019 Posted December 23, 2019 I misread the post thought you wanted to add 2 numbers, we don't do 5+123.34 here in Aus. Quote
asra Posted December 23, 2019 Author Posted December 23, 2019 (edited) HELLO All, I don't mean to add numbers, but to add the "+" symbol sorry for my language Edited December 23, 2019 by asra Quote
asra Posted December 23, 2019 Author Posted December 23, 2019 9 hours ago, hanhphuc said: ymg's rtosa Error: too few arguments Quote
hanhphuc Posted December 23, 2019 Posted December 23, 2019 1 hour ago, asra said: Error: too few arguments you must supply 3 arguments in the function assume your input causes error (rtosta 1234.56 ) (rtosta 1234.56 22 ) (rtosta 1234.56 2 2 ) ; must use space Quote
asra Posted December 24, 2019 Author Posted December 24, 2019 ;; rtosta by ymg September 2013 ; ;; ; ;; Arguments: sta Real number to format as a Station ; ;; unit 1 for Imperials, ; ;; 2 for Metrics. ; ;; prec Integer for number of decimals ; ;; ; ;; Examples: (rtosta 0 1 0) -> "0+00" (rtosta 1328.325 1 2) -> "13+28.33" ; ;; (rtosta 0 2 0) -> "0+000" (rtosta 1328.325 2 2) -> "1+328.33" ; ;; ; ;; If sta is negative, format is as follow: ; ;; (rtosta -1328.325 1 2) -> "13-28.33" ; ;; (rtosta -1328.325 2 2) -> "1-328.33" ; ;; ; (defun rtosta (sta unit prec / str a b ) (rtosta 0 2 0) (setq str (rtos (abs sta) 2 prec)) (while (< (strlen str) (if (= prec 0) (+ unit 2) (+ prec (+ unit 3)))) (setq str (strcat "0" str)) ) (setq a (if (= prec 0) (- (strlen str) unit) (- (strlen str) prec (+ unit 1))) b (substr str 1 (- a 1)) a (substr str a) ) (strcat b (if (minusp sta) "-" "+") a) (princ) ) like this? Quote
hanhphuc Posted December 24, 2019 Posted December 24, 2019 (edited) On 12/24/2019 at 1:21 PM, asra said: like this? Please DO NOT modify the function!!! copy again click -> here! That's why you got error!! (defun rtosta (sta unit prec / str a b ) (rtosta 0 2 0) <-- remove this!!! <snippet> (princ) ;<-- why ?? ) it seems you have zero knowledge in LISP? try this example: (defun c:test ( / TEXT WORD NUMBER OBJECT ) (vl-load-com) (while (setq TEXT (car (entsel "\nSelect TEXT.. "))) (setq OBJECT (vlax-ename->vla-object TEXT)) (if (and (vlax-property-available-p OBJECT 'TextString) (setq NUMBER (read (vla-get-TextString OBJECT ))); atof (numberp NUMBER) ) (vla-put-Textstring OBJECT (rtosta NUMBER 2 2)) )(princ "\nNUMBER please!!") ) ) (princ) ) for multiple texts 1.use ssget for selection 2.loop repeat many examples, just search & learn Edited December 26, 2019 by hanhphuc symbol 'OBJECT' localized Quote
asra Posted December 24, 2019 Author Posted December 24, 2019 (edited) (defun rtosta (sta unit prec / str a b ) (setq str (rtos (abs sta) 2 prec)) (while (< (strlen str) (if (= prec 0) (+ unit 2) (+ prec (+ unit 3)))) (setq str (strcat "0" str)) ) (setq a (if (= prec 0) (- (strlen str) unit) (- (strlen str) prec (+ unit 1))) b (substr str 1 (- a 1)) a (substr str a) ) (strcat b (if (minusp sta) "-" "+") a) ) (defun c:test ( / TEXT WORD NUMBER ) (vl-load-com) (while (setq TEXT (car (entsel "\nSelect TEXT.. "))) (setq OBJECT (vlax-ename->vla-object TEXT)) (if (and (vlax-property-available-p OBJECT 'TextString) (setq NUMBER (read (vla-get-TextString OBJECT ))); atof (numberp NUMBER) ) (vla-put-Textstring OBJECT (rtosta NUMBER 2 0)) )(princ "\nNUMBER please!!") ) ) (princ) ) OK, its works thanks, so much....... what if in selecting text not one by one, but at the same time a lot of text ? Edited December 24, 2019 by asra Quote
asos2000 Posted December 24, 2019 Posted December 24, 2019 (defun c:test ( / TEXT WORD NUMBER ) (vl-load-com) (if (setq sset (ssget '((0 . "text")))) (repeat (setq cnt (sslength sset)) (setq TEXT (ssname sset (setq cnt (1- cnt)))) (setq OBJECT (vlax-ename->vla-object TEXT)) (if (and (vlax-property-available-p OBJECT 'TextString) (setq NUMBER (read (vla-get-TextString OBJECT ))); atof (numberp NUMBER) ) (vla-put-Textstring OBJECT (rtosta NUMBER 2 0)) )(princ "\nNUMBER please!!") ) ) ) (princ) ;; rtosta by ymg September 2013 ; ;; ; ;; Arguments: sta Real number to format as a Station ; ;; unit 1 for Imperials, ; ;; 2 for Metrics. ; ;; prec Integer for number of decimals ; ;; ; ;; Examples: (rtosta 0 1 0) -> "0+00" (rtosta 1328.325 1 2) -> "13+28.33" ; ;; (rtosta 0 2 0) -> "0+000" (rtosta 1328.325 2 2) -> "1+328.33" ; ;; ; ;; If sta is negative, format is as follow: ; ;; (rtosta -1328.325 1 2) -> "13-28.33" ; ;; (rtosta -1328.325 2 2) -> "1-328.33" ; ;; ; (defun rtosta (sta unit prec / str a b ) (setq str (rtos (abs sta) 2 prec)) (while (< (strlen str) (if (= prec 0) (+ unit 2) (+ prec (+ unit 3)))) (setq str (strcat "0" str)) ) (setq a (if (= prec 0) (- (strlen str) unit) (- (strlen str) prec (+ unit 1))) b (substr str 1 (- a 1)) a (substr str a) ) (strcat b (if (minusp sta) "-" "+") a) ) Quote
BIGAL Posted December 25, 2019 Posted December 25, 2019 (edited) Just a different approach 5846.234 divide 1000 = 5.846234 the fix = 5 so add + then multiple decimal part by 1000 and add back on 5+846.234 obviously playing with numbers and strings. Edited December 25, 2019 by BIGAL Quote
hanhphuc Posted December 25, 2019 Posted December 25, 2019 1 hour ago, BIGAL said: Just a different approach 5846.234 divide 1000 = 5.846234 the fix = 5 so add + then multiple decimal part by 1000 and add back on 5+846.234 obviously playing with numbers and strings. not quite.. Try 1.234 divide 1000 = 0.001234 fix 0 & back 0.001234 x1000 = 1.234 0+1.234 it should be 0+001.234 slightly tweak, but i ignore unit normally we use this format as decimal (defun _rtosta (x prec / i n) (setq n (abs (/ x 1e3)) i (* 1e3 (- n (fix n)))) (strcat (itoa (abs (fix n))) (if (minusp x) "-" "+") (cond ((< i 10.) "00") ((< i 100.) "0") (t "") ) (rtos i 2 prec ) ) ) (_rtosta 1.234 3) "0+001.234" wishing you a Merry X'mas p/s: my company sucks! still a working day Quote
BIGAL Posted December 25, 2019 Posted December 25, 2019 Thanks did not test just and idea. To the family Christmas dinner now. 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.