Author Topic: Is Table Cell Empty  (Read 947 times)

0 Members and 1 Guest are viewing this topic.

cmwade77

  • Swamp Rat
  • Posts: 1443
Is Table Cell Empty
« on: November 06, 2020, 08:01:12 PM »
Ok, I have this code from Lee Mac that gets the block name from a cell, if the cell type is a block and is empty, it returns an error.
Code: [Select]
;; Get Table Cell Block  -  Lee Mac
;; Returns the Block Definition associated with a given table cell
(defun LM:blocknamefromtablecell ( tab row col / Block)
  ;; Active Document  -  Lee Mac
  ;; Returns the VLA Active Document Object
  (defun LM:acdoc nil
      (eval (list 'defun 'LM:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object))))
      (LM:acdoc)
  )
  (eval
      (list 'defun 'LM:getcellblock '( tab row col )
          (if
              (and
                  (wcmatch (getenv "PROCESSOR_ARCHITECTURE") "*64*")
                  (vlax-method-applicable-p tab 'getblocktablerecordid32)
              )
              (list 'vla-objectidtoobject32 (LM:acdoc) '(vla-getblocktablerecordid32 tab row col))
              (list 'vla-objectidtoobject   (LM:acdoc) '(vla-getblocktablerecordid   tab row col))
          )
      )
  )
  (setq Block (LM:getcellblock tab row col))
  (if Block
    (vla-get-name Block)
    nil
  )
);End LM:blocknamefromtablecell

I thought I could use vla-isempty function to determine if the cell is empty, but it always returns that the cell is empty, even if it has a block in it.
Code: [Select]
;; Get Table Cell Block  -  Lee Mac
;; Returns the Block Definition associated with a given table cell
(defun LM:blocknamefromtablecell ( tab row col / Block)
  ;; Active Document  -  Lee Mac
  ;; Returns the VLA Active Document Object
  (defun LM:acdoc nil
      (eval (list 'defun 'LM:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object))))
      (LM:acdoc)
  )
  (if (not (vla-isempty tab row col))
    (progn
      (eval
          (list 'defun 'LM:getcellblock '( tab row col )
              (if
                  (and
                      (wcmatch (getenv "PROCESSOR_ARCHITECTURE") "*64*")
                      (vlax-method-applicable-p tab 'getblocktablerecordid32)
                  )
                  (list 'vla-objectidtoobject32 (LM:acdoc) '(vla-getblocktablerecordid32 tab row col))
                  (list 'vla-objectidtoobject   (LM:acdoc) '(vla-getblocktablerecordid   tab row col))
              )
          )
      )
      (setq Block (LM:getcellblock tab row col))
    )
  )
  (if Block
    (vla-get-name Block)
    nil
  )
);End LM:blocknamefromtablecell

Anyone have any ideas on how to fix this so that it returns nil if there is no block? I suppose I could also write an error handler, but that doesn't feel like the right way to handle this, as I do need to check if the cell is truly empty for other reasons.