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,
Solved! Go to Solution.
Solved by 3wood. Go to Solution.
Hi,
Assuming the "numbers" are in a list :
(mapcar '(Lambda(x)(strcat (substr x 1 1) "+" (substr x 2))) numberList)
Gaston Nunez
@lsg.tech wrote:
....
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.
....
Are they always four digits before the decimal point? The function gasty1001 posted would appear to require that. If some might be five or more, it would need to be done differently, involving apply (fix) to the conversion of the text to a real number, in order to find out how many characters there are before the decimal point, before deciding where to insert the + sign. [I'm assuming there should be three digits between the + sign and the decimal point, since they look like stationing numbers, but maybe that's not what you want.] If any have only three before the decimal point, should they be left alone or have 0+ added at the beginning? For two, maybe 0+0? Etc.
EDIT: I thought this idea sounded familiar -- look here.
Further Edit: That is built for whole numbers, so it would need to be adjusted if you have decimal components.
An adjustment of the function in that link, to allow for decimal places [minimally tested]:
(defun station (numstr)
(setq intlen (strlen (itoa (atoi numstr))))
(while (< intlen 4)
(setq
numstr (strcat "0" numstr)
intlen (1+ intlen)
); setq
); while
(strcat
(substr numstr 1 (- intlen 3))
"+"
(substr numstr (- intlen 2))
); strcat
); defun
Usage:
Command: (station "1.2345")
"0+001.2345"
Command: (station "12345.0")
"12+345.0"
Command: (station "2563")
"2+563"
@lsg.tech wrote:
....The numbers are actually already in my drawing and I want to find and replace all coordinates with the above format.
....
It's just a matter of finding them, applying a function like (station) to each one to come up with a new text content, and assigning that new value to it. That's not difficult, but some questions:
Would the User select the Text objects to process [or, say, an area in which the routine would find all such objects], or would you want it to find all of them without User input?
If the latter, would there ever be any Text objects that could represent integer or real numerical values but that are not stationing numbers, and should therefore not be thus adjusted? How would they be distinguishable from the ones that should be? A specific Layer or Style or something?