esam Posted July 12, 2017 Posted July 12, 2017 hi all i looking for lisp that can calculate a sum of cells by clicking on the cell i want. i have many tables that i have to make sum for every colum and its difecult to do this foe every table some openion ??!! sorry about my english Quote
BIGAL Posted July 12, 2017 Posted July 12, 2017 A google should find an answer but if you want a sum above a cell via lisp you can get the last row number of a table and then say ask how many gaps down and put sum function in that cell. I dont have an answer but sure some one will. Pretty sure it was something like vla-get-rows is to bottom of table. Need header info as well as you need to subtract from total rows. I would check cells for a value so you get true last value but need to check all columns. If enter a row number bigger than table then add rows then add sum formula. Quote
SLW210 Posted July 12, 2017 Posted July 12, 2017 I moved your thread to the AutoLISP, Visual LISP & DCL Forum. Quote
maratovich Posted July 12, 2017 Posted July 12, 2017 Try it. But this is not lisp, not vba. This program. SumTable.zip Quote
BIGAL Posted July 15, 2017 Posted July 15, 2017 Had a bit of time so thought I would have a go in lisp, credit though to Lee Ambrosius for get cell picked. Just pick top of column cell to be summed, this is very much a version 1 as I can see a few questions coming. I am sure can do the pick cell a bit better using a entsel. ;; Example shows how to pick a single table cell on screen and change its value. ;; This example demonstrates the ActiveX properties/methods HitTest, ;; GetCellType, GetText and SetText. ;; original code by Lee Ambrosius 2015 (defun SelectTableCell ( / pick vHeight vWidth lwrLeft uprRight vector SS_TABLES cnt eMax cellValueOrg) ;; Ask the user for a point on screen (if (/= (setq pick (vlax-3d-point (getpoint "\nSelect Cell to START sum from: "))) nil) (progn ;; Get the corners of the screen display to build our selection set (setq vHeight (getvar "viewsize")) (setq vWidth (* (/ (nth 0 (getvar "screensize")) (nth 1 (getvar "screensize"))) vHeight)) (setq lwrLeft (list (- (nth 0 (getvar "viewctr")) (/ vWidth 2)) (- (nth 1 (getvar "viewctr")) (/ vHeight 2)) 0)) (setq uprRight (list (+ (nth 0 (getvar "viewctr")) (/ vWidth 2)) (+ (nth 1 (getvar "viewctr")) (/ vHeight 2)) 0)) ;; Get the current display orientation (setq vector (vlax-make-safearray vlax-vbDouble '(0 . 2))) (vlax-safearray-fill vector '(1 1 1)) (setq vector (vlax-make-variant vector)) ;; Select all the table objects visible on screen (if (setq SS_TABLES (ssget "C" lwrleft uprright (list (cons 0 "ACAD_TABLE")))) (progn (setq cnt 0 eMax (sslength SS_TABLES) ) ;; Step through all the items in the selection set (while (> eMax cnt) ;; Geta table object from the selection set (setq tableObj (vlax-ename->vla-object (ssname SS_TABLES cnt))) ;; Return values for what cell was picked in (setq row 0 col 0) ;; Below is also a sample to see if a valid cell is picked ;; (vla-select table pick vector vector 5 5 :vlax-false 'row 'col) ;; Check to see if a valid cell was picked (if (= (vla-hittest tableObj pick vector 'row 'col) :vlax-true) (progn ;; Get out of the loop (setq cnt (1+ eMax)) ;; Check to see what the Cell Type is (Text or Block) (if (= (vla-GetCellType tableObj row col) acTextCell) ;; Let's get the value out exit with row - col (setq cnt eMax) ) ) ) (setq cnt (1+ cnt)) ) ) ) ) ) (princ) ) ; defun ; A is chr 65 (defun addsum-table ( / tableObj row rows col cols ) (SelectTableCell) (setq rows (vla-get-rows tableobj)) (setq cols (vla-get-columns tableobj)) (alert (strcat (rtos rows 2 0) " " (rtos cols 2 0))) (vla-InsertRows tableobj rows (vla-GetRowHeight tableobj (1- rows)) 2);; 3 number of rows (setq rows (- (vla-get-rows tableobj)1 )) ; do a re alpha row column here (SETQ ALPHA (CHR (+ 65 COL ))) (setq ans (strcat "=sum" "(" ALPHA (RTOS ROW 2 0) ":"ALPHA (RTOS ROWS 2 0) ")")) (vla-settext tableobj rows col ans) ) (addsum-table) Quote
esam Posted July 16, 2017 Author Posted July 16, 2017 I WANT SUM ALL THE COLUM TO THE CELL BELOW "TOTAL" the table not always 7 rows it may any numbers of rows Quote
esam Posted July 16, 2017 Author Posted July 16, 2017 its good . but i want it sum to autocad not an external windows and write the sum in the cell i want Quote
maratovich Posted July 16, 2017 Posted July 16, 2017 esam Specify who you are contacting. Read this thread, it can come in handy for a quick fix: http://www.cadtutor.net/forum/showthread.php?101028-What-does-that-code-really-cost Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.