Message 1 of 49
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Is there a Lisp that can sum two texts and bring the total to the next text?
Solved! Go to Solution.
Is there a Lisp that can sum two texts and bring the total to the next text?
Solved! Go to Solution.
Lisp does not work properly in this section!
For example, adding 1 + 76.84 with 100.45 gives the result: 0 + 277.29 !!!
Partial slope
adding 1 + 76.84 with 100.45
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
Unit is metric
For example
1(km)+234(m).56(cm)
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
I am not one of the robots you're looking for
This Drawing
You may send .lsp file may be correct!
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
The truth is that you are wonderful.
You worked very hard and took the time.
Thank you very much.
Thanks to the rest of the friends.
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.
please explain more
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
This seems interesting!
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
please tell me what row comply with it
Second numerical Text object to have content changed to sum with First: