.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Casting DBobject to entity

3 REPLIES 3
Reply
Message 1 of 4
insiaiftiqhar
830 Views, 3 Replies

Casting DBobject to entity

this piece of code always gives "invalidcode exception". I tried both Ctype and DIrectCast.

Dim currentEntity As Entity = Nothing
                            Try
                                ' currentEntity = CType(myT.GetObject(id, OpenMode.ForRead), Entity)
                                currentEntity = DirectCast(myT.GetObject(id, OpenMode.ForRead), Entity)
                            Catch exp As OverflowException
                                Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("OverflowException")
                            Catch exp As InvalidCastException
                                Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("InvalidCastException")
                            End Try

Attached is the full function, I am trying to read all the " coincidence constraints" in a  drawing

Thanks in advance!

 

 

3 REPLIES 3
Message 2 of 4

Hi,

 

 

Your loop scans through the BlockTable, so <id> represents the ObjectID for a BlockTableRecord. A BlockTableRecord is no entity (not derived from ...), so it can't be casted from DbObject to Entity.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 4

Thank you for the response . How do I go about converting a blocktable reference to a block entity?  I need the entity to find its dependencies.

Message 4 of 4

Hi,

 

>> How do I go about converting a blocktable reference to a block entity?

It's difficult, if we don't use the wordingbased on the API.

If you want to search for the blockdefinition (= BlockTableRecord) then you can use your loop through the BlockTable as you do and verify the ObjectID or the Name or whatever you need to find the correct block-definition,

 

If you want to search for block-insertions (= BlockReference) then you might

  • use your <blocktablerecordobject>.GetBlockReferenceIDs to get all references in your drawing.
  • get the block-insertions could be to create a filtered selectionset (>>>click<<<).

 

HTH, - alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost