Jump to content

Adding numbers together in text strings


BrianTFC

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

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