Can you do math in a text object?

Can you do math in a text object?

atuckerJKU9U
Enthusiast Enthusiast
619 Views
22 Replies
Message 1 of 23

Can you do math in a text object?

atuckerJKU9U
Enthusiast
Enthusiast

Hey all, I assume a lisp for something like this exists, it's just hard to search for.  I have a tree survey with thousands of trees, and I need to add the values of multi trunk trees together and replace with the new value.  In the image below, I want the 6",6" to say 12" instead, and the 6",7" to say 13" instead.  Typically we do this separately in a spreadsheet, but in this case I need it to be in the drawing.  Anybody know of a lisp that would do this?  Currently they are dtext, could convert them to mtext if that would help.  EG 6",6" is a single dtext.  Doing find and replace beforehand to get rid of commas, inches, adding a plus, all no problem.  Thanks!

 

atuckerJKU9U_0-1756130065951.png

 

0 Likes
Accepted solutions (1)
620 Views
22 Replies
Replies (22)
Message 2 of 23

paullimapa
Mentor
Mentor

So you only need the text that contain a comma “,” in a selection set or entire drawing to be added showing only the total text in inches?

Could you provide a sample dwg?


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 23

atuckerJKU9U
Enthusiast
Enthusiast

Here's the drawing.  The texts are on a bunch of different layers.  Yes, any text that has a comma would need the numbers within added together.

0 Likes
Message 4 of 23

komondormrex
Mentor
Mentor

check this out

(entmod (subst (cons 1 (strcat (itoa (cal (vl-string-translate "\"," " +" (cdr (assoc 1 (setq text_dxf (entget (car (entsel "\nPick dtext, comma separated"))))))))) "\"")) (assoc 1 text_dxf) text_dxf))
0 Likes
Message 5 of 23

paullimapa
Mentor
Mentor

There’s no drawing attached


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 6 of 23

atuckerJKU9U
Enthusiast
Enthusiast

Did the attachment show up? It's being weird on my end and I can't see that it uploaded.

0 Likes
Message 7 of 23

paullimapa
Mentor
Mentor

You’ll have to use your browser to accesss the forum to attach files


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 8 of 23

atuckerJKU9U
Enthusiast
Enthusiast

Sorry, I can't program well enough to put that in a lisp.  I did try it on the command line and it didn't work.  Plus it would only let me select one at a time.  Needs to select multiple, there are hundreds of text objects to change.  I selected that long string of numbers right below the box. 

atuckerJKU9U_0-1756132880455.png

 

0 Likes
Message 9 of 23

atuckerJKU9U
Enthusiast
Enthusiast

I was able to get it to attach to the original message.  Look there.

0 Likes
Message 10 of 23

komondormrex
Mentor
Mentor

try to run cal command before. should help. 

0 Likes
Message 11 of 23

komondormrex
Mentor
Mentor
Accepted solution

or this custom command

(arxload "geomcal")
(defun c:sum_text_comma (/ text_dxf)
  (foreach text (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget '((0 . "text") (1 . "*`,*"))))))
    (entmod (subst (cons 1 (strcat (itoa (cal (vl-string-translate "\"," " +" (cdr (assoc 1 (setq text_dxf (entget text))))))) "\"")) (assoc 1 text_dxf) text_dxf))
  )
)

updated - missed reverse quote in the text content filter.

0 Likes
Message 12 of 23

atuckerJKU9U
Enthusiast
Enthusiast

Ah, it did work after the cal command!  Still not solved as I need to do hundreds at once.  I could figure out how to get that into a lisp, and probably to select multiple, but I have no idea how to make it add back the text to the right object when multiple were selected.

0 Likes
Message 13 of 23

komondormrex
Mentor
Mentor

check message 11

0 Likes
Message 14 of 23

komondormrex
Mentor
Mentor

need to open your dwg) 

0 Likes
Message 15 of 23

atuckerJKU9U
Enthusiast
Enthusiast

Message 11 works perfect, and so fast!!!  Thanks so much!

Message 16 of 23

paullimapa
Mentor
Mentor

Updated @komondormrex @atuckerJKU9U 

FYI, I noticed that you have in that sample drawing at least one situation:

A foot symbol instead of an inch symbol followed by a comma:

paullimapa_1-1756182502367.png

In this situation it would cause @komondormrex to error out and not process the rest of the selection set.

Perhaps you may want to use the FIND command to locate all matching situations and replace it with the proper symbol:
paullimapa_6-1756183298970.png

 

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 17 of 23

atuckerJKU9U
Enthusiast
Enthusiast

You are correct about that.  This is common with surveyor files, quotes instead of parenthesis, varying numbers of spaces.  Will definitely have to keep an eye on the end product to look for items like that.  I will probably run it then search for commas to find problems.  Thanks for the heads up!

0 Likes
Message 18 of 23

Kent1Cooper
Consultant
Consultant

@paullimapa wrote:

....

A foot symbol instead of an inch symbol followed by a comma:

....

In this situation it would cause @komondormrex to error out and not process the rest of the selection set.


You could also prevent the error-out by filtering not just for Text containing a comma, but instead containing [anything leading plus] a number and an inch mark and a comma and a number [plus anything trailing].  That would mean the example 10',14" would be filtered out, so it would not be processed, but it would not prevent processing of the rest.

But that alone would not filter out one that had the erroneous foot mark after the second number.  So it might be better to filter for a number and an inch mark and a comma and a number and a wildcard * for a possible second digit and an inch mark.

Kent Cooper, AIA
Message 19 of 23

paullimapa
Mentor
Mentor

I agree so something like this would definitely filter out unwanted symbols:

(ssget '((0 . "text") (1 . "*\"`,*\"")))

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 20 of 23

Sea-Haven
Mentor
Mentor

I had a similar problem finding wrong text, so added a Error function zoom to the spot where the problem is and then the user can fix, hopefully the code will be able to be rerun getting further through.

 

This is an example only, not a solution. looks at possible error in two functions. The error name is set in the function.

 

(defun *error* (errmsg)
(if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
 (princ (strcat "\nError: " errmsg))
 )
 (cond 
 ((= errname "slopes")
 (progn
 (command "zoom" "C" pt1 25)
 (command "pline" pt2 "w" 0.075 0.075 pt3 pt4 pt5 "c")
 (command "chprop" (entlast) "" "c" 1 "")
 (alert "look for pline")
 )
 )
 ((= errname "renblock")
 (progn
  (command "zoom" "C" pt 25)
  (command "line" "0,0" pt "")
  (alert (strcat "I= " (rtos i 2 0) "  Error in rename block"))
 )
 )
 )
 (setq *error* nil)
 (princ)
)

 

 

0 Likes