lisp program to add text values-fractions etc??

Discussion in 'AutoCAD' started by R. Hamm, Apr 23, 2008.

  1. R. Hamm

    R. Hamm Guest

    anyone know where I can find a lsp program where I can select existing
    text in the drawing,
    eg.
    12'-2 1/2"
    3 1/2"
    13' 4 3/8"
    and it adds it all up for me?
    I searched with no luck yet.
    Thanks in advance!
    Ramey
     
    R. Hamm, Apr 23, 2008
    #1
  2. R. Hamm

    strawberry Guest

    Hmm, are these text objects or something else, e.g. dims?
     
    strawberry, Apr 24, 2008
    #2
  3. R. Hamm

    strawberry Guest

    Anyway, I don't have a complete solution, however, this routine from
    Cadalyst should get you started:

    ; ----- ADDNUM.LSP -----
    ; CADalyst Oct. 1991, p. 84
    ; TIP #703

    ; Adds numbers by pick.

    (defun C:ADDNUM (/ ENT CT ANX SNUM SLEN E EE X)
    (prompt "\nPick numbers to add: (CANNOT HAVE COMMAS) ")
    (setq ENT (ssget)) ; pick text
    (setq CT 0 ; initialize counts
    ANX 0)
    (setq SNUM (ssname ENT CT)) ; get first piece of text
    (setq SLEN (sslength ENT)) ; get number of pieces
    (while (<= (1+ CT) SLEN) ; loop through selection set
    (setq SNUM (ssname ENT CT) ; get next number's ENAME
    E (entget SNUM) ; get entity data
    EE (cdr (assoc 1 E)) ; get text value
    X (atof EE)) ; convert string to real
    (setq ANX (+ ANX X) ; add number to base
    CT (1+ CT)) ; increment counter
    )
    (princ "\nTotal = ")(princ (rtos ANX 2 4)) ; print in decimal form.
    (princ)
    )


    and the distof function can convert architectural fractions to real
    numbers:

    eg:
    (distof "1'-5 1/2\"" 4)
    17.5

    Put them together, stir it around a bit and hey presto!?! Anyway, let
    us know how you get on.

    Oh, and this function from Bill Kramer's AutoCADet's Guide to Visual
    Lisp converts distance by testing all unit types (apparently)

    (DEFUN CONVERTDISTANCE (S / LU RES TMP)
    (SETQ LU 1)
    (REPEAT 5 ;Five types to test
    (SETQ TMP (DISTOF S LU)
    LU (1+ LU))
    (IF TMP (SETQ RES TMP)))
    RES)
     
    strawberry, Apr 24, 2008
    #3
  4. R. Hamm

    strawberry Guest

    I tried this earlier but it didn't seem to work. I tried it again just
    now and it worked perfectly, so go figure!?!

    ; ----- ADDNUMX.LSP -----
    ; CADalyst Oct. 1991, p. 84 with a tiny adaptation from strawberry
    ; TIP #703

    ; Adds numbers by pick.

    (defun C:ADDNUMX (/ ENT CT ANX SNUM SLEN E EE X)
    (prompt "\nPick numbers to add: (CANNOT HAVE COMMAS) ")
    (setq ENT (ssget)) ; pick text
    (setq CT 0 ; initialize counts
    ANX 0)
    (setq SNUM (ssname ENT CT)) ; get first piece of text
    (setq SLEN (sslength ENT)) ; get number of pieces
    (while (<= (1+ CT) SLEN) ; loop through selection set
    (setq SNUM (ssname ENT CT) ; get next number's ENAME
    E (entget SNUM) ; get entity data
    EE (cdr (assoc 1 E)) ; get text value
    X (distof EE 4)) ; convert string to real
    (setq ANX (+ ANX X) ; add number to base
    CT (1+ CT)) ; increment counter
    )
    (princ "\nTotal = ")(princ (rtos ANX 2 4)) ; print in decimal form.
    (princ)
    )
     
    strawberry, Apr 24, 2008
    #4
  5. R. Hamm

    strawberry Guest

    So, I guess this is a more thorough solution:

    ; ----- ADDNUMX.LSP -----
    ; CADalyst Oct. 1991, p. 84 with a tiny adaptation from strawberry
    ; TIP #703

    ;A 'distance conversion' function (from Bill Kramer)
    (DEFUN CONVERTDISTANCE (S / LU RES TMP)
    (SETQ LU 1)
    (REPEAT 5 ;Five types to test
    (SETQ TMP (DISTOF S LU)
    LU (1+ LU))
    (IF TMP (SETQ RES TMP)))
    RES)

    ; Adds numbers by pick.

    (defun C:ADDNUMX (/ ENT CT ANX SNUM SLEN E EE X)
    (prompt "\nPick numbers to add: (CANNOT HAVE COMMAS) ")
    (setq ENT (ssget)) ; pick text
    (setq CT 0 ; initialize counts
    ANX 0)
    (setq SNUM (ssname ENT CT)) ; get first piece of text
    (setq SLEN (sslength ENT)) ; get number of pieces
    (while (<= (1+ CT) SLEN) ; loop through selection set
    (setq SNUM (ssname ENT CT) ; get next number's ENAME
    E (entget SNUM) ; get entity data
    EE (cdr (assoc 1 E)) ; get text value
    X (CONVERTDISTANCE (EE))) ; convert string to real
    (setq ANX (+ ANX X) ; add number to base
    CT (1+ CT)) ; increment counter
    )
    (princ "\nTotal = ")(princ (rtos ANX 2 4)) ; print in decimal form.
    (princ)
    )
     
    strawberry, Apr 25, 2008
    #5
  6. R. Hamm

    YDOD Guest

    Perhaps you could consider an alternative approach. I had a similar problem,
    coming up with the total length of different size pipes on a drawing of
    ornamental handrail. I used a different layer for the centreline of each
    pipe, isolated each layer and then used a lisp called "tlen" to total the
    length of each size pipe.
     
    YDOD, Apr 25, 2008
    #6
  7. R. Hamm

    R. Hamm Guest

    YES!
    With the distof added it works good enough!
    Thanks much, all
    Ramey
     
    R. Hamm, Apr 29, 2008
    #7
  8. R. Hamm

    strawberry Guest

    Top-posting corrected.

    You're welcome.

    Curiously, while the routine works fine on my Vista workstation, it
    fails on my XP workstation. No idea why.
     
    strawberry, Apr 29, 2008
    #8
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.