Jump to content

Sum selection of AutoCAD table values


sivapathasunderam

Recommended Posts

Have a look here, https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-extract-text-values-from-an-autocad-table-to-a-drawing/td-p/7269002.

 

As far as i can tell you can't click directly on the text in a table to copy its contents into a LISP variable (I don't use tables a lot, I might be wrong). In the link there are 2 routines, Demo which will grab the value of a cell if you click the edge of the cell (right edge and lower edge mostly but this is a bit variable.

 

The other funciton, somefunc grabs all the text in a table which might work for you better.

 

Have a look and see if either of these work for you as a start. Can make up the rest of the LISP if it is.

 

 

EDIT

The first option for somefunc gives the table texts, the second one gives just the values, I think go with the first one

 

 

 

EDIT (Again)

I might be wrong, just found out I have a thing that selects the texts it clicks on - however look at the somefunc above and see if that will be a good start for you

Edited by Steven P
Link to comment
Share on other sites

Just putting this here to come back to later, copied and pasted from my library of stuff

 

Uses nentsel to select the contents. Need to do something like Lee Macs unformat on the table values, make a loop to select all similar values and then make up the table

 

 

(defun getent ( aprompt / enta entb pt )
  (princ "\n")
  (setq enta (car (nentsel aprompt)))
  (setq pt (cdr (assoc 10 (entget enta))) )

;;;;fix for nenset or entsel requirements
  (setq entb (last (last (nentselp pt))))

  (if (and (/= entb nil) (/= (type entb) 'real) )
    (progn
      (if (wcmatch (cdr (assoc 0 (entget entb))) "ACAD_TABLE,*DIMENSION,*LEADER")(setq enta entb))
    )
  )
  enta
)


(defun c:TableText ( / MyEnt )
  (cdr (assoc 1 (entget (getent "Select Table Cell Text"))))
)

 

Link to comment
Share on other sites

Tried to post yesterday look at Lee-mac pick cell in table allows selection of a cell by picking the value displayed.

;; 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 c:SelectTableCell ( / pick vHeight vWidth lwrLeft uprRight vector
                                           SS_TABLES cnt eMax tableObj row col cellValueOrg)
  
  ;; Ask the user for a point on screen
  (if (/= (setq pick (vlax-3d-point (getpoint "\nSelect Cell to edit: "))) 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)

                 
            ;; 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)
                  (progn
                    ;; Let's get the value out
                    (setq cellValueOrg (vla-GetText tableObj row col))

                    ;; Change the current value
                    (vla-SetText tableObj row col "Revised Text")
                    (vla-Update tableObj)
                    (alert "Cell text was changed.")
          
                    ;; Restore the original value
                    (vla-SetText tableObj row col cellValueOrg)
                    (vla-Update tableObj)
                    (alert "Cell text was changed back to the original value.")
                    (setq cnt eMax)
                  )
                )
              )
            )
            (setq cnt (1+ cnt))
          )
        )
      )
    )
  )
 (princ)
)

 

  • Like 1
Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...