sakrado Posted April 4, 2013 Posted April 4, 2013 hi everyone i want to sum only number in text or mtext for example -> EBA 12 (21) NDBR(25.56)....=0.2 IT'S MTEXT -> FD 12 (102) IT'S MTEXT -> NDBR 21 (2 PIPE DUCT) IT'S MTEXT -> (X1=25.32) IT'S TEXT (X2=54.21) IT'S TEXT TOO AND I WANT TO GET RESULT ->12+21+25.56+0.2=... ->12+102=... ->21+2=... ->SUM TEXT AND TEXT 1+25.32+2+54.21=... ->SUM MTEXT AND TEXT ->SUM MTEXT AND MTEXT I WANT MAKE IT SELECT BY OBJECT. AND CAN APPLY TO EVERY DRAWING. ANYONE CAN HELP ME? SEE MY DWG FILE BELOW NEED LISP TO SUM THIS FILE.dwg Quote
ReMark Posted April 4, 2013 Posted April 4, 2013 There are custom lisp routines that will do this. A quick Internet search should easily turn some of them up. Quote
Costinbos77 Posted April 4, 2013 Posted April 4, 2013 (edited) Collect and compare each character and if they are numbers you store them and they added. (defun c:test () (or (vl-load-com)) (if (setq i 0 sel (ssget (list '(0 . "TEXT,MTEXT")) ) ) ; "_X" (cons 8 layer) (progn (setq lsel (sslength sel) ) (princ (strcat "\n Texts : " (itoa lsel)) ) (while (< i lsel) (setq nmo (vlax-ename->vla-object (ssname sel i)) txt (vla-get-TextString nmo) ) (if (= (vla-get-ObjectName nmo) "AcDbMText") (setq txt ([color=red]LM:UnFormat[/color] txt nil) ) ) ; if (setq ltxt (strlen txt) j 1 no "" ts "" s 0) (while (<= j ltxt) (if (member (setq c (substr txt j 1) ) '("." "0" "1" "2" "3" "4" "5" "6" "7" "8" "9")) (setq no (strcat no c) ) (if (/= no "") (setq s (+ s (atof no)) ts (strcat ts "+" no) no "") ) ; if ) ; if member (setq j (1+ j) ) ) ; wh (setq s (+ s (atof no)) ts (strcat ts "+" no) ) (if (/= ts "") (write-line (strcat "\n Object " (itoa i) " ; " (substr ts 2) " = " (rtos s 2 5) " ;")) ) ; if (setq i (1+ i) ) ) ; wh )) ; if (princ) ) ; end Code has not been tested. To go right to Mtext, you need load LM:UnFormat function http://lee-mac.com/unformatstring.html Edited April 4, 2013 by Costinbos77 Quote
ReMark Posted April 4, 2013 Posted April 4, 2013 On my first try I found this. Scroll down to CarlB's reply where he modified the posted routine to include both Text and MText. http://www.eng-tips.com/viewthread.cfm?qid=336013 Quote
pBe Posted April 4, 2013 Posted April 4, 2013 Collect and compare each character and if they are numbers you store them and they added. Thats how i would've approach it too, but then i realize for text string like "NBDR 50 (2PIPE)" that will give you 50+2. Waiting on the OP to give more explanation. Quote
Costinbos77 Posted April 4, 2013 Posted April 4, 2013 (edited) pBe, Check details of OP: -> NDBR 21 (2 PIPE DUCT) IT'S MTEXT . . . ->21+2=... In my opinion, the same problem will be given to: -> (X1=25.32) IT'S TEXT (X2=54.21) IT'S TEXT TOO . . . . ->SUM TEXT AND TEXT 1+25.32+2+54.21=... but it is specified. It can make a criterion for which only written numbers in sequence: (nomber) eg. (2), be taken into account, or to avoid 'nomber =' (X1= or X2=) Edited April 4, 2013 by Costinbos77 Quote
ReMark Posted April 4, 2013 Posted April 4, 2013 Thats how i would've approach it too, but then i realize for text string like "NBDR 50 (2PIPE)" that will give you 50+2. Waiting on the OP to give more explanation. Well sometimes one has to be careful what one asks for. When the genie in the bottle grants you three wishes think carefully and remember the law of unintended consequences. Quote
pBe Posted April 4, 2013 Posted April 4, 2013 (edited) pBe, Check details of OP:.... Thats what i'm driving at. Somehow it doesnt make sense. I guess there's more to it than just ADD the numbers. Well sometimes one has to be careful what one asks for. When the genie in the bottle grants you three wishes think carefully and remember the law of unintended consequences. True that. Edited April 4, 2013 by pBe Quote
Costinbos77 Posted April 4, 2013 Posted April 4, 2013 As I said, you can make some restrictions. Quote
marko_ribar Posted April 4, 2013 Posted April 4, 2013 Thats how i would've approach it too, but then i realize for text string like "NBDR 50 (2PIPE)" that will give you 50+2. Waiting on the OP to give more explanation. Wired request by OP... pBe, this could also be 5+0+2=7 (how will we know if 50 is 50 and not 5,0... M.R. Quote
pBe Posted April 4, 2013 Posted April 4, 2013 Wired request by OP... pBe, this could also be 5+0+2=7 (how will we know if 50 is 50 and not 5,0... M.R. I see, if i were to guess, this "NDBR 21 (2 PIPE DUCT)" would mean 21*2 ?!? but from the previous thread started by the OP, similar string values are grouped together then values added, not sure where this new request comes into play. I have not got a reply from the other thread so i decided not to pursue it any further. the solution Is fairly easy really. I agree with Costinbos77 to "make some restrictions" , the values should make some kind of "real world" results. I cant quite put my finger on it, I just wish (1 of the three wishes Remark ) the OP would give us more info. Cheers Quote
Recommended Posts
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.