Author Topic: sum text contained number ?  (Read 4207 times)

0 Members and 1 Guest are viewing this topic.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2140
  • class keyThumper<T>:ILazy<T>
Re: sum text contained number ?
« Reply #15 on: May 25, 2016, 06:40:40 AM »

I s'pose the question really is
"Who is responsible for the data .... should the user or the program enforce matching of the suffix text ? "
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

dussla

  • Bull Frog
  • Posts: 297
Re: sum text contained number ?
« Reply #16 on: May 25, 2016, 08:18:35 AM »
Sorry friend
 I would like to help other
But my skill and head is not good really
Other friends is very smart .
My poor skill  didnot help other friend still
Pls understand me
always i think really help




dussla,

You've been visiting here for 9 or 10  years.
Have you learnt how to read code yet ?
How much code writing have you done.
How many posts have you made trying to help people.

The reason you are getting the result you get is because of the color of your text.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: sum text contained number ?
« Reply #17 on: May 25, 2016, 08:47:18 AM »
Reading :idea: ronjons code I think the (shifted) Y coordinates are causing this issue.

eh, shift happens
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

ronjonp

  • Needs a day job
  • Posts: 7529
Re: sum text contained number ?
« Reply #18 on: May 25, 2016, 09:09:22 AM »
thank you   friends

but there is some problem ~~
pls check ~~~
sorry for my many ask

if you see image  , you can see error~
dussla,

Please read the comments in the code, that's why I put them on just about every line.

@ Lee .. you nailed it LOL

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: sum text contained number ?
« Reply #19 on: May 25, 2016, 12:10:11 PM »

Fabricio28

  • Swamp Rat
  • Posts: 670
Re: sum text contained number ?
« Reply #20 on: June 29, 2016, 10:56:52 AM »
Like so?  :)
Code - Auto/Visual Lisp: [Select]
  1. (defun c:sumitupyo (/ fuzz ip n1 o o2 o3 r ss suf txt x)
  2.   ;; 05.24.2016 RJP
  3.   ;; Sums up text items on similar Y plane
  4.   (if
  5.     (and ;; Get text
  6.          (setq ss (ssget ":L" '((0 . "Text"))))
  7.          ;; Convert selection set to list
  8.          (setq ss (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))))
  9.          ;; Sort by smalles X coordinate
  10.          (setq
  11.            ss (vl-sort ss
  12.                        '(lambda (a b)
  13.                           (< (car (vlax-get a 'insertionpoint)) (car (vlax-get b 'insertionpoint)))
  14.                         )
  15.               )
  16.          )
  17.     );; While we have a list
  18.      (while (setq o (car ss))
  19.        ;; Remove the first item
  20.        (setq ss (cdr ss))
  21.        ;; Get insertion point
  22.        (setq ip (vlax-get o 'insertionpoint))
  23.        ;; Get texstring
  24.        (setq txt (vla-get-textstring o))
  25.        ;; Convert text to number
  26.        (setq n1 (atof txt))
  27.        ;; Get suffix
  28.        (setq suf (substr txt (1+ (strlen (rtos n1)))))
  29.        ;; Fuzz value = 1/2 text height
  30.        (setq fuzz (* 0.5 (vla-get-height o)))
  31.        ;; Find the other item in the list on the same Y plane within a fuzz value
  32.        (setq o2
  33.               (vl-remove-if-not '(lambda (x) (equal (cadr ip) (cadr (vlax-get x 'insertionpoint)) fuzz))
  34.                                 ss
  35.               )
  36.        )
  37.        ;; Remove those items from the list
  38.        (mapcar '(lambda (x) (setq ss (vl-remove x ss))) o2)
  39.        ;; Add the values
  40.        (setq
  41.          r (strcat
  42.              (rtos
  43.                (apply '+ (mapcar '(lambda (x) (atof (vla-get-textstring x))) (append (list o) o2)))
  44.              )
  45.              suf
  46.            )
  47.        )
  48.        ;; If we've added items, make a copy of the last text object & put summed value
  49.        (if o2
  50.          (progn (setq o3 (vlax-invoke (last o2) 'copy))
  51.                 (vla-put-color o3 3)
  52.                 (vlax-invoke o3
  53.                              'move
  54.                              ip
  55.                              (polar ip
  56.                                     (angle ip (vlax-get (car o2) 'insertionpoint))
  57.                                     (distance ip (vlax-get (car o2) 'insertionpoint))
  58.                              )
  59.                 )
  60.                 (vla-put-textstring o3 r)
  61.          )
  62.        )
  63.      )
  64.   )
  65.   (princ)
  66. )

Very nice Ron,

Congratulation :)

Fabricio

ronjonp

  • Needs a day job
  • Posts: 7529
Re: sum text contained number ?
« Reply #21 on: June 29, 2016, 11:22:18 AM »
Thanks :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC