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

sum field in a table Is it possible?

4 REPLIES 4
Reply
Message 1 of 5
andresep82
935 Views, 4 Replies

sum field in a table Is it possible?

i have one table make which field from block. Is  possible sum?

4 REPLIES 4
Message 2 of 5
dicra
in reply to: andresep82

Can you upload the table?

Message 3 of 5
andresep82
in reply to: andresep82

 

yes

 

example file

Message 4 of 5
Hallex
in reply to: andresep82

Try this one from my oldies, badly designed though

 

(defun C:TBSUM(/ acsp adoc blk_obj col en header headers hgt i line row sset table tablelist tbl_data tmp)
 (vl-load-com) 
(or adoc
    (setq adoc (vla-get-activedocument
		 (vlax-get-acad-object)))
    )
(or acsp
    (setq acsp (vla-get-block (vla-get-activelayout adoc)))
    )
(setq hgt 0.12)

(if (setq sset (ssget '((0 . "insert")(2 . "Superficie"))))
  (progn
    (while (setq en (ssname sset 0))
      (setq blk_obj (vlax-ename->vla-object en))
      (foreach att (vlax-invoke blk_obj 'getattributes)
	(setq tmp (cons (vla-get-textstring att) tmp)))
      (setq tbl_data (append tbl_data (list(reverse tmp))))
      (setq tmp nil)
      (ssdel en sset))))
(setq tablelist (mapcar '(lambda (x)
			   (list (car x)(atof (vl-string-subst "." "," (cadr x)))))tbl_data))

(setq tablelist (vl-sort  tablelist '(lambda (a b)(< (car a)(car b)))))
(setq table (vlax-invoke acsp 'addtable
	      (getpoint "\nPick table location: ")
	      (+ 3(length tablelist))
	      (length (car tablelist))
	      (* hgt 1.5)
	      (* hgt 8)
	      ))
(vla-put-regeneratetablesuppressed table :vlax-true)
(vla-setcelltextheight table 0 0 5) 
  (vla-settext table 0 0 "TITLE")
  (vla-setcelltextheight table 0 0 (* hgt 2))
(setq headers (list "Name" "Sup."))
(setq col 0)
(while (setq header (car headers))
   (vla-setcelltextheight table 1 col (* hgt 1.25))
  (vla-settext table 1 col header)
  (setq col ( 1+ col))
  (setq headers (cdr headers))
  )
(setq row 2)
(while (setq line (car  tablelist))
   (setq col  0)
  (foreach item line
       (vla-setcelltextheight table row col (* hgt 1.25))
  (vla-settext table row col item)
    (setq col (1+ col)))
  (setq row (1+ row))
  (setq tablelist (cdr tablelist)))
(vla-settext table row 0 "Total=")
  (vla-setcelltextheight table row 0 (* hgt 1.25))
(vla-settext table row 1 (strcat "=SUM(B2:B" (itoa (1- (vlax-get-property table 'rows)))")" ))
  (vla-setcelltextheight table row 1 (* hgt 1.25))
  (setq i 0)
 (while (< i (vlax-get-property table 'rows))
   (vla-setrowheight table i (* hgt 1.5))(setq i (1+ i)))
  (vla-put-VertCellMargin table (* hgt 0.1))
    (vla-put-HorzCellMargin table (* hgt 0.1))
(vlax-put-property table 'height (* (vlax-get-property table 'rows)(* hgt 1.5)))
 (vlax-put-property table 'width (* (vlax-get-property table 'columns)(* hgt 8))) 
(vla-put-regeneratetablesuppressed table :vlax-false)
  (princ)
)

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 5 of 5
andresep82
in reply to: andresep82

yeah¡¡¡ work¡¡¡ I have throw something similar, badly designed too,I am a beginner   Smiley LOL

 

 

 

(vl-load-com)
(defun C:tablasup ( / *MS* attValue attValue2 CNT I LST MYTABLE PT1 ROW SSET TLST)

(setq altura_texto 5)

  (setq lst '()
 i 0
 *ms* (vla-get-modelspace
             (vla-get-activedocument
             (vlax-get-acad-object)))
  )
  ; prompt the user to select closed polylines
  (princ "\n Seleciona bloques ")
  (if (setq sset (ssget '((0 . "INSERT"))))
    
    (progn
   
	 (repeat (setq cnt (sslength sset))
      (setq attValue (GetAttributeValue (ssname sset i) "DEPENDENCIA"))
       (setq attValue2 (GetAttributeValue (ssname sset i) "SUP_UTIL")) 
	(setq tlst (list  attValue attValue2))
      (setq lst (cons tlst lst))
        (setq i (1+ i))
      )
     
      (setq pt1 (getpoint "\nPunto inserción tabla: "))
      ; add the new table
      (setq myTable (vla-AddTable 
                    *ms* 
                    (vlax-3d-point pt1)
                    (+ 3 cnt)
                    3               ;numero de columnas
                    0.5            ; altura filas
                    4))         ; anchura columnas

      ; the next three lines set the header text
      (vla-setText mytable 0 0 "SUPERFICE UTIL")
      (vla-setText mytable 1 0 "Dependencia")
      (vla-setText mytable 1 1 "Sup.")
      (setq row 2)
      
    (setq colObj (vlax-create-object "AutoCAD.AcCmColor.19"))
    (vla-SetRGB colObj 98 136 213)
    (vla-SetBackgroundColor myTable (+ acHeaderRow acTitleRow) colObj)

     (vla-put-Vertcellmargin myTable 0.05) ;margen vertical de texto
      (vla-put-Horzcellmargin myTable  0.15) ;margen horizontal de texto

(vla-setTextheight myTable acTitleRow 0.15) ;altura texto titulo
(vla-setTextheight myTable acHeaderRow 0.1) ;altura texto cabecera
(vla-setTextheight myTable acDataRow 0.11) ;altura texto celdas
(vla-setAlignment myTable acTitleRow acMiddleCenter) 
(vla-setAlignment myTable acHeaderRow acMiddleCenter) 
(vla-setAlignment myTable acDataRow acMiddleright)
(vla-SetRowHeight myTable 0 0.5) 
(vla-SetRowHeight myTable 1 0.5) 
(vla-SetColumnWidth myTable 0 1.5)
(vla-SetColumnWidth myTable 1 1)
(vla-SetColumnWidth myTable 2 0.5)

      (foreach item lst
        (vla-setText mytable 
				row 0  

				(Car item)
						)
(vla-setText mytable 
				row 1  

					(Cadr item)
						)

(vla-setText mytable 
				row 2 

					(strcat "m²")
						)

		(vla-SetRowHeight myTable row  0.5) ;altura de fila insertada
     
        (setq row (1+ row))
      )    

      ; On the last row, total up the area
     (vla-setText mytable
                   row 
                   0
                   (strcat "Total=")
				)

(vla-setText mytable
                   row 1
(strcat "%<\\AcExpr (Sum(B3:B" (itoa  (+ 2 cnt)) ")) \\f \"%lu2%pr2%ps%zs8\">%")
		)

(vla-setText mytable
                   row 2
		(strcat "m²")
			)
	(vla-SetRowHeight myTable row  0.5) ;altura de fila insertada
                   
      (vlax-release-object myTable)      
      (vlax-release-object *ms*)      
    ); end progn

   ; if no closed polylines were selected, 
   ; end the program with this message
    (princ "\nNo has seleccionado bloques. ")
  ); end if
  (princ)
); end defun

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Get Attribute Value  -  Lee Mac
;; Returns the value held by the specified tag within the supplied block, if present.
;; Arguments:
;; blk - [ent] Block (Insert) Entity Name
;; tag - [str] Attribute TagString
;; Returns: [str] Attribute value, else nil if tag is not found.

(defun GetAttributeValue (blk tag / val enx)
    (while
      (and
        (null val)
        (= "ATTRIB"
           (cdr (assoc 0 (setq enx (entget (setq blk (entnext blk))))))
        )
      )
       (if (= (strcase tag) (strcase (cdr (assoc 2 enx))))
         (setq val (cdr (assoc 1 enx)))
       )
    )
  )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

                          

 

To export to excell is better for me that "m²"  will be another colunm.

 

but de field lost,and  the alone table is not updated alone,but it does not matter because meke very faster wich this lips  Smiley Very Happy

 

The solution is a reactor right?

 

sorry for my english.

 

 

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

Post to forums  

Autodesk Design & Make Report

”Boost