+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Super Moderator Cad64's Avatar
    Computer Details
    Cad64's Computer Details
    Operating System:
    Windows 7 Profesional x64
    Computer:
    XI Computers
    Motherboard:
    Asus P8Z77-V Pro
    CPU:
    Intel Core I7 3770K 4.1 Ghz Quad Core 3rd Gen
    RAM:
    8GB DDR3 @ 1333MHz
    Graphics:
    Nvidia GeForce GTX 570 1280MB GDDR5
    Primary Storage:
    SATAII 500GB 7200 RPM
    Secondary Storage:
    Western Digital My Book Studio Edition II - 2TB capacity
    Monitor:
    HPf2105 21" LCD Widescreen & Cintiq 21ux
    Discipline
    Multi-disciplinary
    Cad64's Discipline Details
    Occupation
    Freelance Digital Artist
    Discipline
    Multi-disciplinary
    Details
    In a nutshell, I create 3D models from the client's CAD files or design sketches which I then use to produce high quality rendered images. Click on the link in my signature to view my portfolio. I'm always looking for work, so let me know if you need any custom models or renders. :)
    Using
    3ds Max 2011
    Join Date
    Feb 2006
    Location
    Southern California
    Posts
    9,016

    Default Calculating the sum of selected numbers

    Hey guys, I'm looking for a routine that will add up the total of selected dtext numbers. These numbers are large square footage totals like 47,604.27 and 23,705.39.

    I have the routine below, (that I got from the Cadalyst site), but it treats the commas like decimal points and rounds off to the nearest whole number. So when it adds the two amounts above it returns a total of 70.0 instead of 71,309.66.

    If anyone has a routine, or can modify the routine below so that it can add large numbers with commas, and not round off the total, I will be forever grateful.

    Thanks for your time.

    Code:
    ;Tip1369A.LSP:   ADD.LSP   Add Selected Numbers   (P.K.Yousuf)
    
    ;Prepared by P.K.Yousuf 
    
    (defun C:ADD (/ S1 LG INDEX A B C D)
      (setq S1    (ssget)
            LG    (sslength S1)
            INDEX 0
            C     0
      ) ;_ end of setq
      (while (/= INDEX LG)
        (setq A (entget (ssname S1 INDEX))
              D (cdr (assoc 0 A))
        ) ;_ end of setq
        (if (= D "TEXT")
          (progn
            (setq B (atof (cdr (assoc 1 A)))
                  C (+ C B)
            ) ;_ end of setq
          ) ;_ end of progn
        ) ;_ end of if
        (setq INDEX (1+ INDEX))
      ) ;_ end of while
      (princ "\nTotal Value: ")
      (princ C)
      (princ)
    )   ;end defun
    Freelance Digital Artist
    Personal Website: ( Updated 03/21/2014 ) --->
    http://www.rdeweese.com/

    "Work Smart, Not Hard"

  2. #2
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    16,743

    Default

    Give this a try:

    Code:
    (defun c:AddText ( / i r s x )
        (if (setq s (ssget '((0 . "TEXT") (1 . "*#*"))))
            (progn
                (setq r 0.0)
                (repeat (setq i (sslength s))
                    (setq x (cdr (assoc 1 (entget (ssname s (setq i (1- i)))))))
                    (while (wcmatch x "*`,*")
                        (setq x (vl-string-subst "" "," x))
                    )
                    (if (setq x (distof x))
                        (setq r (+ r x))
                    )
                )
                (princ (strcat "\nTotal: " (rtos r)))
            )
        )
        (princ)
    )
    The printed result will be dependent on your settings of LUNITS / LUPREC
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  3. #3
    Super Moderator Cad64's Avatar
    Computer Details
    Cad64's Computer Details
    Operating System:
    Windows 7 Profesional x64
    Computer:
    XI Computers
    Motherboard:
    Asus P8Z77-V Pro
    CPU:
    Intel Core I7 3770K 4.1 Ghz Quad Core 3rd Gen
    RAM:
    8GB DDR3 @ 1333MHz
    Graphics:
    Nvidia GeForce GTX 570 1280MB GDDR5
    Primary Storage:
    SATAII 500GB 7200 RPM
    Secondary Storage:
    Western Digital My Book Studio Edition II - 2TB capacity
    Monitor:
    HPf2105 21" LCD Widescreen & Cintiq 21ux
    Discipline
    Multi-disciplinary
    Cad64's Discipline Details
    Occupation
    Freelance Digital Artist
    Discipline
    Multi-disciplinary
    Details
    In a nutshell, I create 3D models from the client's CAD files or design sketches which I then use to produce high quality rendered images. Click on the link in my signature to view my portfolio. I'm always looking for work, so let me know if you need any custom models or renders. :)
    Using
    3ds Max 2011
    Join Date
    Feb 2006
    Location
    Southern California
    Posts
    9,016

    Default

    Thanks a lot Lee, it works perfectly. As usual, you are the man.
    Freelance Digital Artist
    Personal Website: ( Updated 03/21/2014 ) --->
    http://www.rdeweese.com/

    "Work Smart, Not Hard"

  4. #4
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    16,743

    Default

    Cheers Rod, you're very welcome
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  5. #5
    Forum Deity pBe's Avatar
    Computer Details
    pBe's Computer Details
    Operating System:
    Windows XP
    Discipline
    Construction
    pBe's Discipline Details
    Discipline
    Construction
    Details
    Camp Construction planning and details
    Using
    AutoCAD 2009
    Join Date
    Apr 2010
    Posts
    2,605

    Default

    Whilst i was trying to figure out what to do with the "," thingy. Lee came and went.
    **** Gone in 60 seconds ****

    Nice code btw Lee

  6. #6
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    16,743

    Default

    Registered forum members do not see this ad.

    Cheers pBe
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

Similar Threads

  1. Convert integers numbers into real numbers, introducing decimal separator.
    By teknomatika in forum AutoLISP, Visual LISP & DCL
    Replies: 8
    Last Post: 3rd Sep 2010, 04:07 pm
  2. Calculating lengths
    By jamiegreig1987 in forum AutoCAD General
    Replies: 2
    Last Post: 7th May 2009, 11:50 am
  3. Selected lines not appearing on screen as being selected.
    By mrjangles in forum AutoCAD Drawing Management & Output
    Replies: 7
    Last Post: 17th Feb 2009, 05:42 pm
  4. Calculating Volume
    By djc in forum AutoCAD 3D Modelling & Rendering
    Replies: 2
    Last Post: 5th Sep 2006, 10:44 pm
  5. adding numbers to numbers
    By philk in forum AutoLISP, Visual LISP & DCL
    Replies: 4
    Last Post: 23rd Feb 2006, 05:45 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts