Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Lisp routine for adding symbols

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
Anonymous
1537 Views, 8 Replies

Lisp routine for adding symbols

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,

8 REPLIES 8
Message 2 of 9
hgasty1001
in reply to: Anonymous

Hi,

 

Assuming the "numbers" are in a list :

 

(mapcar '(Lambda(x)(strcat (substr x 1 1) "+" (substr x 2))) numberList)

 

Gaston Nunez

 

 

Message 3 of 9
Kent1Cooper
in reply to: Anonymous


@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.

Kent Cooper, AIA
Message 4 of 9
Anonymous
in reply to: Kent1Cooper

Kent1Cooper you are right the + sign will always be in the hundred position meaning 3 places after the decimal place. I want to add a 0+ or 0+0 for beginnings that have no valves in those positions.
Message 5 of 9
Kent1Cooper
in reply to: Anonymous

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"

Kent Cooper, AIA
Message 6 of 9
Anonymous
in reply to: Kent1Cooper

Hi Kent,

The numbers are actually already in my drawing and I want to find and replace all coordinates with the above format.

Thanks for all your help.
Message 7 of 9
Kent1Cooper
in reply to: Anonymous


@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?

Kent Cooper, AIA
Message 8 of 9
Anonymous
in reply to: Kent1Cooper

We would just want the routine to run itself, but you raise a valid point is that all the text is in the same layer and we don't want to change them all. We can create a separate layer for these coordinates.
Message 9 of 9
3wood
in reply to: Anonymous

Please try attached ALTEXT.vlx.

Settings as below:

altext_2.png

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost