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

0 Members and 1 Guest are viewing this topic.

GDF

  • Water Moccasin
  • Posts: 2021
Add Dtext to get Total
« on: July 29, 2009, 02:59:48 PM »
Does anyone have a routine for adding dtext in architectural units "feet" and "inches" to get a total?
The one below only does decimal without reading the inches.

14'-0" + 12'-4" = 26.00

Code: [Select]
(defun ADD-TXT  (/ s1 lg index count c x a d totalarea atext apoint)
  (setq S1    (ssget)
        LG    (sslength S1)
        INDEX 0
        COUNT 0
        C     0)
  (while (/= INDEX LG)
    (setq X (ssname S1 INDEX)
          A (entget X)
          D (cdr (assoc 0 A)))
    (if (= D "TEXT")
      (progn (setq B     (atof (cdr (assoc 1 A)))
                   C     (+ C B)
                   COUNT (1+ COUNT))))
    (setq INDEX (1+ INDEX))) 
  (setq TOTALAREA (rtos C 2 2))
  (setq ATEXT (strcase (strcat "" TOTALAREA ""))) 
  (while (not apoint)
    (setq APOINT (getpoint "\n* Pick Location for Text in Drawing... *"))   
    (command "text" "j" "bl" APOINT 9 0 ATEXT))       
  (princ))
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2019x64 Windows 10x64

Spike Wilbury

  • Guest
Re: Add Dtext to get Total
« Reply #1 on: July 29, 2009, 03:19:04 PM »
Hi Gary


Maybe if it is used something like:

(rtos (+ (distof "14'-0" 4)(distof "12'-4" 4)) 4 2) ;; having dimzin=3
"26'-4\""

GDF

  • Water Moccasin
  • Posts: 2021
Re: Add Dtext to get Total
« Reply #2 on: July 29, 2009, 03:25:48 PM »
Luis

I'm looking to pick the dtext objects in a drawing to get the total, then place that total as dtext in the drawing.

Code: [Select]
;;;this code will do it for dimensions
;;;Peter Jamtgaard
(defun ADIMIT  (/ CNT ENAM EOBJ SSET)
  (prompt "\n* Select All Dimensions to Total in Imperial Units *")
  (setq CNT 0
        SUM 0)
  (if (setq SSET (ssget (list (cons 0 "DIMENSION"))))
    (progn (command ".dim1" "update" SSET "")
           ;;added this line
           (repeat (sslength SSET)
             (setq ENAM (ssname SSET CNT)
                   CNT  (1+ CNT)
                   EOBJ (vlax-ename->vla-object ENAM))
             (vl-catch-all-apply
               '(lambda (X) (setq SUM (+ SUM (vla-get-measurement X))))
               (list EOBJ)))
           ;;(princ (strcat "\n" (rtos SUM 4 6)))
           (princ (strcat "\n* Total Dimension = " (rtos SUM 4 6) " *"))))
  (prin1))
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2019x64 Windows 10x64

Spike Wilbury

  • Guest
Re: Add Dtext to get Total
« Reply #3 on: July 29, 2009, 03:36:43 PM »
need to practice.... there you go sir - super mickey mouse stuff - and assumes the strings are valid dimension data(s)

Code: [Select]
(defun C:ATXT ()
  (setq total 0.0)
  (while (setq ent (car (entsel "\nSelect text: ")))
    (progn
      (setq obj (vlax-ename->vla-object ent))
      (setq str (vla-get-textstring obj))
      (setq total (+ (distof str 4) total))
    )
  )
  (princ "\nTotal=") (princ (rtos total 4 2)) (princ)
)

Lee Mac

  • Seagull
  • Posts: 12313
  • London, England
Re: Add Dtext to get Total
« Reply #4 on: July 29, 2009, 03:38:27 PM »
Just a quickie  :lol:

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))
      (vla-put-Alignment
        (setq tObj (vla-addText spc tStr
                     (vla-getVariable doc "VIEWCTR")
                       (* (getvar "DIMSCALE") (getvar "DIMTXT"))))
        acAlignmentMiddleCenter)
      (while (eq 5 (car (setq gr (grread 't 5 0))))
        (vla-move tObj
          (vla-get-TextAlignmentPoint tObj) (vlax-3D-point (cadr gr))))
      (vla-delete sel)))
  (princ))
« Last Edit: July 30, 2009, 08:14:28 AM by Lee Mac »

GDF

  • Water Moccasin
  • Posts: 2021
Re: Add Dtext to get Total
« Reply #5 on: July 29, 2009, 03:39:04 PM »
This would work fine if it read dtext objects in imperial units and got a total in imperial units.
Code: [Select]
;;;I am just wondering it it is possible to create a lisp routine that could be used to
;;;tabulate a total distance from text values.  I would like to be able to click each piece
;;;of text and then have AutoCAD return the total
;;;by: Tim Willey

(defun TXCALCIT (/ app cal n l nu1 nu2 nu3 nu4 nu5 tx1 tx2 tx3 tx4)
  (defun get_info ()
    (setq nu1 (entget (ssname cal n)))
    (setq nu2 (cdr (assoc 1 nu1)))
    (setq nu3 (atof nu2))
  )
  (defun addc ()
    (get_info)
    (setq nu4 nu3)
    (setq n (+ 1 n))
    (while (/= l n)
      (get_info)
      (setq nu5 (+ nu4 nu3))
      (setq nu4 nu5)
      (setq n (+ 1 n))
    )
  )
  (defun subc ()
    (get_info)
    (setq nu4 nu3)
    (setq n (+ 1 n))
    (while (/= l n)
      (get_info)
      (setq nu5 (- nu4 nu3))
      (setq nu4 nu5)
      (setq n (+ 1 n))
    )

  )
  (defun multc ()
    (get_info)
    (setq nu4 nu3)
    (setq n (+ 1 n))
    (while (/= l n)
      (get_info)
      (setq nu5 (* nu4 nu3))
      (setq nu4 nu5)
      (setq n (+ 1 n))
    )
  )
  (defun divdc ()
    (get_info)
    (setq nu4 nu3)
    (setq n (+ 1 n))
    (while (/= l n)
      (get_info)
      (setq nu5 (/ nu4 nu3))
      (setq nu4 nu5)
      (setq n (+ 1 n))
    )
  )
  (initget "+ - * /")
  (setq app (getkword
     "\n* What application would you like to do:\(+,-,*,/)"
   )
  )
  (if (or (= app "-") (= app "/"))
    (princ "\n* Don't forget order counts. So pick carefully. *"
    )
  )
  (princ "\nSelect numbers to calculate:")
  (setq cal (ssget '((0 . "TEXT"))))
  (setq n 0)
  (setq l (sslength cal))
  (while (/= l n)
    (get_info)
    (if (= nu3 0.0)
      (progn
(ssdel (ssname cal n) cal)
(setq l (- l 1))
(setq n (- n 1))
      )
    )
    (setq n (+ n 1))
  )
  (setq n 0)
  (setq l (sslength cal))
  (cond
    ((= app "+")
     (addc)
    )
    ((= app "-")
     (subc)
    )
    ((= app "*")
     (multc)
    )
    ((= app "/")
     (divdc)
    )
  )
  (initget "Replace Write")
  (princ "\nAnswer= ")
  (princ nu5)
  (setq tx1
(getkword
  "\n* What do you want do with the answer\(Replace, Write to screen):"
)
  )
  (cond
    ((= tx1 "Replace")
     (setq tx2 (ssget '((0 . "TEXT"))))
     (setq n 0)
     (setq l (sslength tx2))
     (while (/= n l)
       (setq tx3 (entget (ssname tx2 n)))
       (setq tx4 (subst (cons 1 (rtos nu5 2 1)) (assoc 1 tx3) tx3))      
       (entmod tx4)
       (setq n (+ 1 n))
     )
    )
    ((= tx1 "Write")
     (setq nu5 (rtos nu5 2 1))
     (princ "\n* Pick point for text insertion")
     (command "text" "j" "m" pause "" "" nu5)
    )
  )
  (princ)
)
(princ)
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2019x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2021
Re: Add Dtext to get Total
« Reply #6 on: July 29, 2009, 03:44:03 PM »
Perfect
Thank you Luis

need to practice.... there you go sir - super mickey mouse stuff - and assumes the strings are valid dimension data(s)

Code: [Select]
(defun C:ATXT ()
  (setq total 0.0)
  (while (setq ent (car (entsel "\nSelect text: ")))
    (progn
      (setq obj (vlax-ename->vla-object ent))
      (setq str (vla-get-textstring obj))
      (setq total (+ (distof str 4) total))
    )
  )
  (princ "\nTotal=") (princ (rtos total 4 2)) (princ)
)
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2019x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2021
Re: Add Dtext to get Total
« Reply #7 on: July 29, 2009, 03:49:02 PM »
Lee

I could not get yours to work in placing the new dtext total in the drawing.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2019x64 Windows 10x64

Lee Mac

  • Seagull
  • Posts: 12313
  • London, England
Re: Add Dtext to get Total
« Reply #8 on: July 29, 2009, 06:45:50 PM »
Lee

I could not get yours to work in placing the new dtext total in the drawing.

Hmmm... Seems to work fine for me  :?


CAB

  • Global Moderator
  • Seagull
  • Posts: 10376
Re: Add Dtext to get Total
« Reply #9 on: July 29, 2009, 09:11:14 PM »
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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10376
Re: Add Dtext to get Total
« Reply #10 on: July 29, 2009, 11:23:30 PM »
Lee.
Nice routine! The text was too small in my environment.
FYI, Typically 5 units for text size here and DIMSCALE of 48 and DIMTXT of 0.125
Usually I use (* (getvar "DIMSCALE)(getvar "DIMTXT")) for text Size.

« Last Edit: July 29, 2009, 11:26:45 PM by CAB »
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: 12313
  • London, England
Re: Add Dtext to get Total
« Reply #11 on: July 30, 2009, 08:15:11 AM »
Lee.
Nice routine! The text was too small in my environment.
FYI, Typically 5 units for text size here and DIMSCALE of 48 and DIMTXT of 0.125
Usually I use (* (getvar "DIMSCALE)(getvar "DIMTXT")) for text Size.



Thanks Alan  :-)

I normally use "TEXTSIZE", but I have seen "DIMTXT" used recently, but thanks for the heads-up, code updated.

Lee

CAB

  • Global Moderator
  • Seagull
  • Posts: 10376
Re: Add Dtext to get Total
« Reply #12 on: July 30, 2009, 09:35:29 AM »
As you know DIMTXT comes form the Current Dimension Style. The actual dim text size is derived
by (* DIMTXT DIMSCALE) and some use DIMSCALE of ONE but many do not use ONE.
DIMSIZE is the last used text size. Not sure which is more reliable for getting the most desired
text size. I suspect the dimension style may be somewhat constant. Hard to say.
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: 12313
  • London, England
Re: Add Dtext to get Total
« Reply #13 on: July 30, 2009, 09:50:14 AM »
True, I am always wondering which to use, and normally, whichever method I choose, people seem to always come back and say "The Text is to big/small...".

Thanks for the information about the sys vars, I suppose the choice is either TEXTSIZE or (* (getvar "DIMSCALE") (getvar "DIMTXT")), depending on the consistency of either Dimension Style or Text Style.

Lee

CAB

  • Global Moderator
  • Seagull
  • Posts: 10376
Re: Add Dtext to get Total
« Reply #14 on: July 30, 2009, 10:15:59 AM »
That's why I usually ask for a sample DWG. Seems I guess wrong too much of the time.  8-)
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.