有一点时间,所以我想我会有一个Lisp程序,虽然信贷李安布罗修斯得到细胞选择。
只需选择要求和的列单元格顶部,这是非常多的版本1,因为我可以看到接下来的几个问题。
我确信使用entsel可以更好地处理pick单元格。
- ;; 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)
|