+ Reply to Thread
Results 1 to 3 of 3

Thread: Sum attribute

  1. #1
    ImaJayhawk
    Guest

    Default Sum attribute

    Registered forum members do not see this ad.

    I'm trying to write an autolisp program that will sum all the numbers within a block attribute that has a attribute tag called 100. Here's what I tried.

    (defun C:atty (/ en enlist en2 enlist2 sum)
    (setq summy 0)
    (setq ent (ssget ":N" '((0 . "INSERT"))))
    (setq numobj (sslength object))
    (foreach ent
    (progn
    (setq en (car ent))
    (setq enlist (entget en))
    (if (= (cdr (assoc 66 enlist)) 1)
    (progn
    (setq en2 (entnext en))
    (setq enlist2 (entget en2))
    (while (/= (cdr (assoc 0 enlist2)) "SEQEND")
    (if (= (cdr (assoc 2 enlist2)) "100")
    (setq sum (cdr (assoc 1 enlist2)))
    ) ;if assoc 2
    (setq en2 (entnext en2))
    (setq enlist2 (entget en2))
    ) ; while
    ) ; progn
    ) ; if assoc 66
    (setq summy (+ summy sum))
    ) ; progn
    ) ; foreach


    (princ)

    )


    Any help would be appreciated. Thanks.




    ImaJayhawk

  2. #2
    Super Member David Bethel's Avatar
    Discipline
    Multi-disciplinary
    David Bethel's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Commercial Food Service
    Using
    AutoCAD pre 2000
    Join Date
    Dec 2003
    Location
    Newport News, Virginia
    Posts
    1,925

    Default

    Try this:
    -David

    Code:
    (defun c:combav (/ tm ss i en an ad at av vl)
      (initget 1)
      (setq tm (strcase (getstring "\nATTRIB Tag To Add:   ")))
      (and (setq ss 
              (ssget "X" (list (cons 0 "INSERT")
                               (cons 66 1)
                               (cons 67 (if (= (getvar "TILEMODE") 1) 0 1)))))
            (setq i (sslength ss))
            (while (not (minusp (setq i (1- i))))
                   (setq en (ssname ss i)
                         an (entnext en))
                   (while (= "ATTRIB" (cdr (assoc 0 (entget an))))
                          (setq ad (entget an)
                                at (strcase (cdr (assoc 2 ad)))
                                av (cdr (assoc 1 ad)))
                          (if (= at tm)
                              (setq vl (cons (atof av) vl)))
                          (setq an (entnext an)))))
    (apply '+ vl))
    [/code]
    R12 (Dos) - A2K

  3. #3
    ImaJayhawk
    Guest

    Default

    Registered forum members do not see this ad.

    Thanks that works great!



    ImaJayhawk

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