Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Auto sum all attributes inside blocks

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
jacob_mataGKQCJ
604 Views, 8 Replies

Auto sum all attributes inside blocks

I'm looking for a way to auto sum all the attributes in my dwg and if possible, keep a live table of those totals in the dwg. Ideally, I would like to keep a total of the FTG attribute for each block type, as well as a table with the FTG, QTY & MAT (material) attributes so I can determine material totals with a formula that will multiply the ftgs with the qty. If its possible to change them to fields or mtext that will autosum, I'm open to changing the format. I've attached my dwg with the blocks I'm trying to use. Thank You

8 REPLIES 8
Message 2 of 9

Have you tried Dataextraction command to create the Table. Then you can always manually add a row at the bottom then add a formula in the cell to sum the above rows. The Table can also be updated since it’s a Dataextraction 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 3 of 9

yes, I have and it does work. I'm just looking for a live table of the totals to eliminate the need for that step

Message 4 of 9

Provide Autodesk feedback here


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 5 of 9
Sea-Haven
in reply to: jacob_mataGKQCJ

If you have an existing table at any time you can add a row. "Vla-insertrows", so if you have attributes can link via a field to a block attribute cell. 

 

Using a custom make table. So if add more blocks select table then select blocks.

 

 

 

Message 6 of 9
ec-cad
in reply to: jacob_mataGKQCJ

Here's my take on it.

This Lisp will make a .csv file in the current folder, named 'dwgname'+.csv.

Open that .csv, adjust the Column Width as required. Mark and 'Copy' the Cells,

then in Acad drawing ..Right Click, Copyclip/Paste. That gives you an image that is 

in the drawing, and can be saved with it. You may also want to select that image, and

Scale it to suit.

I'm sure Sea-Haven can make up a Lisp that just 'builds' the Table within the .dwg,

and when you need an update, just remove the existing table, and rebuild it.

 

See the drawing attached.

Load the Lisp, and type GO to start it up.

 

ECCAD

 

;; GET_FTG.lsp
 (vl-load-com)
;;
 (defun write_to_csv_file ( S ); send in 'string', formatted as .csv
   (if (findfile OUTFILE)
    (progn
     (setq ofil (open OUTFILE "a"))
     (write-line S ofil)
     (close ofil)
    ); progn
   ); if
   (if (not (findfile OUTFILE))
    (progn
     (setq ofil (open OUTFILE "w"))
;; Header
     (setq O (strcat
        (chr 34) "FTG" (chr 34) ","
        (chr 34) "QUANTIY" (chr 34) ","
        (chr 34) "MATERIAL" (chr 34) ","
        (chr 34) "BLOCKNAME" (chr 34) ",,"
     )); setq/strcat
     (write-line O ofil)
     (write-line S ofil)
     (close ofil)
    ); progn
   ); if
 ); function

;; Search Blocks, get the Attribute Values
;;
 (defun get_FTG_info ( )
  (setq ss nil FTG-TOTAL 0); assures selection set is nil
  (setq ss (ssget "X" (list (cons 0 "INSERT"))))
  (if ss
   (progn
    (setq N 0)
    (repeat (sslength ss)
     (setq ent (entget (ssname ss N))); Entity
     (setq BLKNAME (cdr (assoc 2 ent))); Blockname
     (setq blk (vlax-ename->vla-object (ssname ss N))); Make Object of the Item
     (if (safearray-value (setq atts (vlax-variant-value (vla-getattributes blk))))
      (progn
       (setq atts (vlax-safearray->list (vlax-variant-value (vla-getattributes blk))))
        (foreach att atts
         (setq Tag (strcase (vla-get-tagstring att)))
           (if (= Tag "FTG"); FTG
            (progn
             (setq FTG (strcase (vla-get-textstring att)))
             (if (and (/= FTG nil)(/= FGT ""))
              (progn
               (setq F (atoi FTG))
               (setq FTG-TOTAL (+ FTG-TOTAL F)); SUM
              ); progn
             ); if
            ); progn
           ); if
           (if (= Tag "QTY"); Quantity
            (setq QTY (vla-get-textstring att))
           ); if
           (if (= Tag "MATERIAL"); Material
            (setq MAT (vla-get-textstring att))
           ); if
        ); foreach att
        (map_the_data) ; returns O .. strcat of data
        (write_to_csv_file O)
       ); progn
      ); if safearray
      (setq N (+ N 1))
     ); repeat sslength
    ); progn
   ); if ss
  (princ)
 ); function


 (defun map_the_data ( ); Make a string of the data..
;; Form Output string O
   (setq O (strcat
     (chr 34) FTG (chr 34) ","
     (chr 34) QTY (chr 34) ","
              MAT          ","
     (chr 34) BLKNAME (chr 34) ",,"
   )); setq/strcat
 ); function

;; MAIN .................
(defun C:GO ( ); overall function call
  (setq dwg (getvar "dwgname"))
  (setq dwg (substr dwg 1 (- (strlen dwg) 4))); strip the .dwg
  (setq OUTFILE (strcat (getvar "dwgprefix") dwg ".csv"))
  (setq MAT "" QTY "" FTG "" BLKNAME "" F 0); Init for strings..
;
  (command "_zoom" "e")
  (get_FTG_info)
  (if (> FTG-TOTAL 0)
   (progn
    (setq O (strcat "TOTAL FTG = " (itoa FTG-TOTAL)))
    (write_to_csv_file O)
   ); progn
  ); if
 (princ)
); function C:GO
 (princ "\n")
 (princ "\nType GO to GET FTG's")
 (princ)

 

Message 7 of 9
jacob_mataGKQCJ
in reply to: ec-cad

Thank you. This was very helpful

Message 8 of 9
ec-cad
in reply to: jacob_mataGKQCJ

Thanks for the feedback. Glad to help out.

IF you need any changes, please let us know. I'm sure someone here can help.

 

ECCAD

Message 9 of 9
Sea-Haven
in reply to: jacob_mataGKQCJ

"when you need an update, just remove the existing table, and rebuild it."

 

This is the simplest way making a table with a few hundred rows is like 1 second, you must turn off the display rows as you make the build the table then display it. 3 minutes v's 1 second.

 

 

(vla-put-regeneratetablesuppressed tableobj :vlax-false)

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report