Different handles are returned by (tblobjname "block" "") and (vlas-invoke-method blocks "item" ""), which is rooted in their history.
(tblobjname) returns the block’s "BLOCK" entity, also known as the AcDbBlockBegin object, which rooted in history (i.e. something only existing LISP code could rationalize). This is what (tblsearch "block" ")) used to return elements of.
(vlax-invoke-method blocks "item" "") returns the object Id of the actual Block Table Record, which is generally of greater interest to "modern code". ObjectARX and ActiveX applications should have no (or little) use for AcDbBlockBegin and AcDbBlockEnd entities, they exist only for compatibility reasons.
This code can be used to get to the block object:
(defun c:getToBlock (/ acadApp acadDoc acadBlocks myBlock myBlockHandle)
(if (and (setq e1 (entsel "\nSelect Block Reference: "))
(= (cdr (assoc 0 (entget (car e1)))) "INSERT"))
(progn
(vl-load-com)
(Setq acadApp (vlax-get-acad-object)
acadDoc (vla-get-ActiveDocument acadApp)
acadBlocks (vlax-get-property acadDoc "blocks")
myBlock (vlax-invoke-method acadBlocks "item"
(cdr (assoc 2 (entget (car e1)))))
myBlockHandle (vlax-get-property myBlock "handle"))
(print myBlock)
)
)
(princ)
)

Leave a Reply