Jump to content
BrianTFC

Adding numbers together in text strings

Recommended Posts

BrianTFC

Hi,

 

i was wondering if there was away to add the following with a lisp rountine, i do a lot of material list with this format.

 

5'-3"

6'-4 11/16"

4'-3"

 

the answer would be 15'-10 11/16", i would like to be able to select them and it would add them together. i would appreciate any help.

Share this post


Link to post
Share on other sites
Lee Mac

Very quickly written:

 

(defun c:addtxt ( / i n r s )
   (if (setq s (ssget '((0 . "TEXT") (1 . "*#*"))))
       (progn
           (setq r 0.0)
           (repeat (setq i (sslength s))
               (if (setq n (distof (cdr (assoc 1 (entget (ssname s (setq i (1- i))))))))
                   (setq r (+ n r))
               )
           )
           (princ (strcat "\nTotal: " (rtos r)))
       )
   )
   (princ)
)

 

Will use the settings of LUNITS & LUPREC in your drawing.

Share this post


Link to post
Share on other sites
BrianTFC

Thanks Lee your the Lisp God!!!!!...it worked great...you hit out of the park agian...

Share this post


Link to post
Share on other sites
Lee Mac

You're welcome Brian, cheers :)

Share this post


Link to post
Share on other sites
BrianTFC

Hi Lee, :)

 

You said that it uses the lunits and the luprec, i was wondering if you could use to different types of number in the string and multiply them together? like

 

qty / length / total

 

8 / 3'-8 9/16" / 29'-8 1/2"

 

Brian

Share this post


Link to post
Share on other sites
Lee Mac

Certainly, but I'm afraid I cannot devote any more voluntary time to this project. :)

Share this post


Link to post
Share on other sites
neophoible
Hi Lee, :)

 

You said that it uses the lunits and the luprec, i was wondering if you could use to different types of number in the string and multiply them together? like

 

qty / length / total

 

8 / 3'-8 9/16" / 29'-8 1/2"

 

Brian

 

Brian, originally you asked to add selected text. This Q sounds like a separate request. Now you want to multiply a selected text a certain number of times? Why not just COPY or ARRAY, then select them all and add them that way? It will achieve the same effect without further programming.

Share this post


Link to post
Share on other sites
BIGAL

This conjures all sorts of dramas and it would be seperate program all together we have it so easy in metric 8-1.132 = 9.055 just need to look for the delimeter in this case the -.

 

An answer in your task look for 1st space then remove from text then run Lees program then multiply by the number that was removed. Print answer. I am sure I downloaded a search for character.lsp from Lee's web site. Use Substr find its position then work out the left over text. A better way now is use vl-string-search

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...