Is there a Lisp that can sum two texts and bring the total to the next text?

Is there a Lisp that can sum two texts and bring the total to the next text?

Oliver_C3D
Advocate Advocate
8,347 Views
48 Replies
Message 1 of 49

Is there a Lisp that can sum two texts and bring the total to the next text?

Oliver_C3D
Advocate
Advocate

Is there a Lisp that can sum two texts and bring the total to the next text?

S01.png

0 Likes
Accepted solutions (1)
8,348 Views
48 Replies
Replies (48)
Message 21 of 49

Oliver_C3D
Advocate
Advocate

Lisp does not work properly in this section!

For example, adding 1 + 76.84 with 100.45 gives the result: 0 + 277.29 !!!

0 Likes
Message 22 of 49

devitg
Advisor
Advisor

Please state which  row to add to which row 

0 Likes
Message 23 of 49

Oliver_C3D
Advocate
Advocate

Partial slope 

adding 1 + 76.84 with 100.45

0 Likes
Message 24 of 49

dlanorh
Advisor
Advisor

I did mention that the lisp assumed that the number before the "+" was in thousands of units, so firstly we need to establish whether this is metric chainages (the number before the "+" is in kms) or imperial chainages (the number before the "+" is in 100's of yards)?

 

I am not one of the robots you're looking for

0 Likes
Message 25 of 49

Oliver_C3D
Advocate
Advocate
Unit is metric
For example
1(km)+234(m).56(cm)
0 Likes
Message 26 of 49

devitg
Advisor
Advisor

@Oliver_C3D wrote:

Partial slope 

adding 1 + 76.84 with 100.45


partial slope , to which row 

 

0 Likes
Message 27 of 49

Oliver_C3D
Advocate
Advocate

Hello Dear 

Do you understand where the problem is?

@dlanorh 

0 Likes
Message 28 of 49

dlanorh
Advisor
Advisor

Apologies, I'm in a different time zone.

 

I will try to solve the space issue around the "+" sign so that this is replicated in the final string. Until then, this works mathematically.

 

(defun rh:chg_str (lst n) (+ (* (atoi (car lst)) (expt 10 n)) (atof (cadr lst))))

(defun str_split ( del str / n ) (if (setq n (vl-string-search del str)) (cons (substr str 1 n) (str_split del (substr str (+ n 1 (strlen del))))) (list str)))

; = Sum of Numerical Texts into 2nd one selected
(defun C:SNT2 (/ el1 el2 sum tsum)
  (setq el1 (entget (car (entsel "\nFirst numerical Text object: ")))
        el2 (entget (car (entsel "\nSecond numerical Text object to have content changed to sum with First: ")))
        sum (+ (rh:chg_str (str_split "+" (cdr (assoc 1 el1))) 3) (rh:chg_str (str_split "+" (cdr (assoc 1 el2))) 3))
        tsum (rtos (rem sum 1000) 2 2)
  ); setq
  (setq sum (strcat (if (< sum 1000) "0" (itoa (fix (/ sum 1000)))) "+" (while (< (vl-position 46 (vl-string->list tsum)) 3) (setq tsum (strcat "0" tsum)))))
  (entmod (subst (cons 1 sum) (assoc 1 el2) el2))
  (princ)
);end_defun

 

I am not one of the robots you're looking for

0 Likes
Message 29 of 49

Oliver_C3D
Advocate
Advocate

99.png

0 Likes
Message 30 of 49

dlanorh
Advisor
Advisor
It works in my test drawing. If it doesn't work in yours then I will need a sample drawing in AutoCAD 2010 so I can see what is causing the error, or is this adding a chainage to a non chainage number i.e. 0+123.45 & 5.678

I am not one of the robots you're looking for

0 Likes
Message 31 of 49

Oliver_C3D
Advocate
Advocate

This Drawing

@dlanorh 

0 Likes
Message 32 of 49

Oliver_C3D
Advocate
Advocate

You may send .lsp file may be correct!

0 Likes
Message 33 of 49

dlanorh
Advisor
Advisor
Accepted solution

The drawing is not helpful as I don't know what you are trying to add together. That aside, try this amended version.

 

(defun rh:chg_str (lst n) (+ (* (atoi (car lst)) (expt 10 n)) (atof (cadr lst))))

(defun str_split ( del str / n ) (if (setq n (vl-string-search del str)) (cons (substr str 1 n) (str_split del (substr str (+ n 1 (strlen del))))) (list str)))

; = Sum of Numerical Texts into 2nd one selected
(defun C:SNT2 (/ t1 elst t2 l1 l2 sum tsum p txt)
  (setq t1 (cdr (assoc 1 (entget (car (entsel "\nFirst numerical Text object: ")))))
        t2 (cdr (assoc 1 (setq elst (entget (car (entsel "\nSecond numerical Text object to have content changed to sum with First: "))))))
  )
  (setq l1 (if (vl-position 43 (vl-string->list t1)) (str_split "+" t1) (list "0" t1))
        l2 (if (vl-position 43 (vl-string->list t2)) (str_split "+" t2) (list "0" t2))
        sum (+ (rh:chg_str l1 3) (rh:chg_str l2 3))
        tsum (rtos (rem sum 1000) 2 2)
        p (if (wcmatch t2 "* + *") " + " "+")
  ); setq
  
  (setq sum (strcat 
              (if (< sum 1000) "0" (itoa (fix (/ sum 1000))))
              p
              (if (/= (vl-position 46 (vl-string->list tsum)) 3) (while (< (vl-position 46 (vl-string->list tsum)) 3) (setq tsum (strcat "0" tsum))) tsum)
            )
  )
  (entmod (subst (cons 1 sum) (assoc 1 elst) elst))
  (princ)
);end_defun

 

 

I am not one of the robots you're looking for

0 Likes
Message 34 of 49

Oliver_C3D
Advocate
Advocate

The truth is that you are wonderful.
You worked very hard and took the time.
Thank you very much.

@dlanorh 

 

Thanks to the rest of the friends.

@devitg 

@Kent1Cooper 

@john.uhden 

 

0 Likes
Message 35 of 49

devitg
Advisor
Advisor

I ask what row to add to what row  , as I think it can be made in a automatic way , as 3DFACES enclose all text in a row.  to be add and change to the other row. 

 

0 Likes
Message 36 of 49

Oliver_C3D
Advocate
Advocate

please explain more

0 Likes
Message 37 of 49

devitg
Advisor
Advisor

 

pseudo code

 pick the origin row name  

then pick the nearby 3dface

get the 3dface coordinates 

get all mtext or text  inside such 3dface

make a copy ,  from 000 to 000 and put in a  new layer 

select mtext at the new layer ,  

explode all mtext , not the text                                             

at the new layer there are  only text  at the same insertion point  as the original row 

 

Now pick the text to add row , and  the nearby 3dface that enclose text to add

make such text-ss and copy the same way as before to a new layer 

As the distance and direction from origin text  to text to add shall be some constant value , 

now the lisp could pick both values , and then  assign such new values at the destination or  ROW  to add 

 

Hope you can understand , my english is no so good

 

 

That is why I ask from which row to  get value , to  which row add succh value and change at this row

example 

 

original row : Partial Slope Distance

row to get value 

Progres. Hrz. Distance

and row to set new value 

the same ,   

Progres. Hrz. Distance

 

 

 

 

 

                                          

 

 

 

 

 

 

0 Likes
Message 38 of 49

Oliver_C3D
Advocate
Advocate

This seems interesting!

@dlanorh 

0 Likes
Message 39 of 49

john.uhden
Mentor
Mentor

Hwy, Ron.

Isn't it good enough to...

Command: (vl-string-subst "" "+" "1+234.56")
"1234.56"

?

and then distof?

and then @formatsta?

John F. Uhden

0 Likes
Message 40 of 49

devitg
Advisor
Advisor

please tell me what row comply with it 

 

Second numerical Text object to have content changed to sum with First:
0 Likes