Get Block Name In Table Cell

Get Block Name In Table Cell

DGCSCAD
Collaborator Collaborator
187 Views
3 Replies
Message 1 of 4

Get Block Name In Table Cell

DGCSCAD
Collaborator
Collaborator

I'm looking to get the name of a block in a table cell.

 

This returns: #<variant 0 >

 

(setq test1 (vlax-invoke-method myTable 'GetCellValue 1 10))

 

I'm close, just need a nudge in the right direction.

AutoCad 2018 (full)
Win 11 Pro
0 Likes
Accepted solutions (1)
188 Views
3 Replies
Replies (3)
Message 2 of 4

DGCSCAD
Collaborator
Collaborator

Ok, I wasn't even close. lol

 

Mr Mac had it covered already. This works for my purposes:

(defun c:test ()
(setq table1 (car (_entsel "Please select a Table: ")))
(setq table2 (vlax-ename->vla-object table1))
(setq tbl_blk_nam (LM:blocknamefromtablecell table2 1 10))
)

(defun LM:blocknamefromtablecell ( obj row col / 64p doc )
    (setq 64p (wcmatch (getenv "PROCESSOR_ARCHITECTURE") "*64*")
          doc (vla-get-activedocument (vlax-get-acad-object))
    )
    (eval
        (list 'defun 'LM:blocknamefromtablecell '( obj row col )
            (list 'if '(= acblockcell (vla-getcelltype obj row col))
                (list 'vla-get-name
                    (list
                        (if (and 64p (vlax-method-applicable-p doc 'objectidtoobject32))
                            'vla-objectidtoobject32
                            'vla-objectidtoobject
                        )
                        doc
                        (list
                            (if (and 64p (vlax-method-applicable-p obj 'getblocktablerecordid32))
                                'vla-getblocktablerecordid32
                                'vla-getblocktablerecordid
                            )
                            obj row col
                        )
                    )
                )
            )
        )
    )
    (LM:blocknamefromtablecell obj row col)
)
AutoCad 2018 (full)
Win 11 Pro
0 Likes
Message 3 of 4

Moshe-A
Mentor
Mentor
Accepted solution

@DGCSCAD  hi,

 

check this function

 

enjoy

moshe

 

(defun cell_block_name (row col / adoc pick ename elist AcDbTblObj oid AcDbBlkTblRec bname)
 (setq adoc (vla-get-activedocument (vlax-get-acad-object)))

 (if (and
       (setq pick (entsel))
       (setq ename (car pick))
       (setq elist (entget ename))
       (eq (cdr (assoc '0 elist)) "ACAD_TABLE")
     )
  (progn
   (setq AcDbTblObj (vlax-ename->vla-object (car (entsel))))
   (setq oid (vla-getBlockTableRecordId AcDbTblObj row col))
   (setq AcDbBlkTblRec (vla-objectIdToObject adoc oid))
   (setq bname (vla-get-name AcDbBlkTblRec))

   (vlax-release-object AcDbBlkTblRec)
   (vlax-release-object AcDbTblObj)
   (vlax-release-object adoc)
   
   bname
  ); progn
 ); if
); cell_block_name
0 Likes
Message 4 of 4

DGCSCAD
Collaborator
Collaborator

Hey thanks Moshe!

 

Looking through both yours and Lee's I can understand what I was missing.

 

I see that I needed to get the acad object to apply to the object ID to get the table blocks.

 

I'm a bit fuzzy today, so I appreciate the help.

AutoCad 2018 (full)
Win 11 Pro
0 Likes