Jump to content

Block Definition Object Using AutoLISP


Recommended Posts

There is a function in VLisp - (vlax-ename->vla-object) - that converts an entity name to vla Object.



(vlax-ename->vla-object (tblobjname "layer" "0"))

correctly returns a layer object #<VLA-OBJECT IAcadLayer 000000002abcbb08>


(vlax-ename->vla-object (tblobjname "style" "standard"))

also correctly returns a text style object #<VLA-OBJECT IAcadTextStyle 000000002abcbdd8>



(vlax-ename->vla-object (tblobjname "block" "b1"))


behaves differently and returns entity #<VLA-OBJECT IAcadEntity 000000002b08aea8> and not IAcadBlock object as expected.


We have to use 

  (cdr (assoc 330 (entget (tblobjname "block" "b1"))))

to get the value of Block (definition) object #<VLA-OBJECT IAcadBlock 0000000033f12c18>


I am curious to know the reason of this 'non-standard' behavior.


I believe it has something to do with how AutoCAD internally stores the blocks.


Can anybody explain why and how this happens?

Edited by NirantarVidyarthee
Link to comment
Share on other sites

I don't worry too much about this, a lot of the odd things that happen in LISP are historical and can be traced to the development of Autocad from it's initial release to the current version. Many of these are retained for backwards compatibility.


So yes, the difference is how the data is stored and recorded, I am not an expert at what the difference is and why but I would suspect that the first 2, layer and style are not object definitions. block is the whole object definition  ad contains layer and style as necessary. CAD is off today so I can't confirm but maybe you could check if say a line, circle, or text requires the last method

Link to comment
Share on other sites

Because the tblobjname function returns an AcDbBlockBegin object for the Block Symbol Table so as to facilitate iterating over the block components (until an AcDbBlockEnd object is encountered); the AcDbBlockBegin class is derived from the AcDbEntity class, hence the equivalent ActiveX interface object is an IAcadEntity object.


You can also observe this through the DXF data for the entities - tblobjname will return a BLOCK entity of class AcDbBlockBegin which is derived from the AcDbEntity base class:


    (-1 . <Entity name: 20458ff8900>)
    (0 . "BLOCK")
    (330 . <Entity name: 20458ff88a0>)
    (5 . "3C0")
    (100 . "AcDbEntity")
    (67 . 0)
    (8 . "0")
    (100 . "AcDbBlockBegin")
    (70 . 0)
    (10 0.0 0.0 0.0)
    (-2 . <Entity name: 20458ff88b0>)
    (2 . "test")
    (1 . "")


The parent entity is a BLOCK_RECORD entity of class AcDbBlockTableRecord which is derived from the AcDbSymbolTableRecord base class:


    (-1 . <Entity name: 20458ff88a0>)
    (0 . "BLOCK_RECORD")
    (5 . "3BA")
    (102 . "{ACAD_XDICTIONARY")
    (360 . <Entity name: 20458ff88e0>)
    (102 . "}")
    (330 . <Entity name: 20458fef810>)
    (100 . "AcDbSymbolTableRecord")
    (100 . "AcDbBlockTableRecord")
    (2 . "test")
    (360 . <Entity name: 20458ff8900>)
    (340 . <Entity name: 0>)
    (102 . "{BLKREFS")
    (331 . <Entity name: 20458ff8920>)
    (102 . "}")
    (70 . 4)
    (280 . 1)
    (281 . 0)


  • Like 3
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.

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...