Author Topic: Add Dtext to get Total  (Read 5326 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5238
Re: Add Dtext to get Total
« Reply #45 on: July 30, 2009, 06:32:09 PM »
Even if you right click to end the text selection?  I didn't test it in my '09, only '06.

yep... right,left or enter works

It is because you have it setup to have the shortcut menu with the right click, and I do not.  I just turned it on, and right click worked, but turning it off again, and it won't work.  Alan brought to my attention on one of my polyline routines that uses grread.  At least we know why now.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Lee Mac

  • Seagull
  • Posts: 12390
  • London, England
Re: Add Dtext to get Total
« Reply #46 on: July 30, 2009, 07:09:50 PM »
Just curious, did my approach in reply #31 work for any of you guys?  :-)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10388
Re: Add Dtext to get Total
« Reply #47 on: July 30, 2009, 10:18:04 PM »
Worked in my test.
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

  • Seagull
  • Posts: 12390
  • London, England
Re: Add Dtext to get Total
« Reply #48 on: July 31, 2009, 06:36:27 AM »
Thanks for testing it Alan, hopefully Tim and Gary will get good results also.  :wink:


GDF

  • Water Moccasin
  • Posts: 2055
Re: Add Dtext to get Total
« Reply #49 on: July 31, 2009, 12:03:13 PM »
Thanks a winner Alan!!!!  You can have my prize...  :oops:

Works here to. I would suggest that the new text match the selected in layer and size.
Lee, you have a winner. I will have to study how Alan fixed it....even though it's over my head.

Lee thanks for sharing your routine.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Lee Mac

  • Seagull
  • Posts: 12390
  • London, England
Re: Add Dtext to get Total
« Reply #50 on: July 31, 2009, 12:12:16 PM »
No problem.  :-)

To match layer, color, height:

Code: [Select]
;;  By Lee
;;  Sum the text selected & add new text with the total

(defun c:dPick (/ ss doc spc sel lst tStr tObj gr)
  (vl-load-com)
  (if (setq ss (ssget '((0 . "TEXT"))))
    (progn
      (setq doc (vla-get-ActiveDocument
                  (vlax-get-Acad-Object))
            spc (if (zerop (vla-get-activespace doc))
                  (if (= (vla-get-mspace doc) :vlax-true)
                    (vla-get-modelspace doc)
                    (vla-get-paperspace doc))
                  (vla-get-modelspace doc)))
      (vlax-for Obj (setq sel (vla-get-ActiveSelectionSet doc))
        (setq lst (cons (distof (vla-get-TextString Obj) 4) lst)))
      (setq tStr (rtos (apply '+ (vl-remove-if 'null lst)) 4 2))
      (setq tObj (vla-addText spc tStr (vlax-3d-point '(0 0 0)) 1.))
      (vla-put-Alignment tObj acAlignmentMiddleCenter)
    [color=red]  (foreach prop '(Layer Height Color)
        (vlax-put-property tObj prop
          (vlax-get-property
            (vlax-ename->vla-object (ssname ss 0)) prop)))[/color]
      (while
        (progn
          (setq gr (grread 't 5 0))
          (cond ((eq 5 (car gr))
                 (vla-put-TextAlignmentPoint tObj
                   (vlax-3D-point (trans (cadr gr) 1 0))) t)
                (t nil))))))
  (princ))


GDF

  • Water Moccasin
  • Posts: 2055
Re: Add Dtext to get Total
« Reply #51 on: July 31, 2009, 12:39:07 PM »
Lee

I used Alan"s version to get it to work:

Code: [Select]
(defun c:dPick (/ ss doc spc sel lst tStr tObj gr)
  (vl-load-com)
  (if (setq ss (ssget '((0 . "TEXT"))))
    (progn
      (setq doc (vla-get-ActiveDocument
                  (vlax-get-Acad-Object))
            spc (if (zerop (vla-get-activespace doc))
                  (if (= (vla-get-mspace doc) :vlax-true)
                    (vla-get-modelspace doc)
                    (vla-get-paperspace doc))
                  (vla-get-modelspace doc)))
      (vlax-for Obj (setq sel (vla-get-ActiveSelectionSet doc))
        (setq lst (cons (distof (vla-get-TextString Obj) 4) lst)))
      (setq tStr (rtos (apply '+ (vl-remove-if 'null lst)) 4 2))
      (setq tObj (vla-addText spc tStr (vlax-3d-point '(0 0 0))
                     (*(getvar "DIMSCALE")(getvar "DIMTXT"))))
      (vla-put-Alignment tObj acAlignmentMiddleCenter)

      (foreach prop '(Layer Height Color)
        (vlax-put-property tObj prop
          (vlax-get-property
            (vlax-ename->vla-object (ssname ss 0)) prop)))

      (while (and(/= 3 (car (setq gr (grread 't 5 0)))) (listp (cadr gr)))
          (vla-put-TextAlignmentPoint tObj (vlax-3D-point (trans (cadr gr) 1 0)))
      )
    ))
  (princ))


Thanks again my friend.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Lee Mac

  • Seagull
  • Posts: 12390
  • London, England
Re: Add Dtext to get Total
« Reply #52 on: July 31, 2009, 12:41:52 PM »
Not a problem, I wasn't sure which version worked for who (they all seem to work for me  :-) )

Glad you got what you wanted  8-)

Lee