.NET

Reply
Contributor
insiaiftiqhar
Posts: 19
Registered: ‎06-21-2012
Message 1 of 4 (283 Views)

Casting DBobject to entity

283 Views, 3 Replies
11-20-2012 02:43 PM

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!

 

 

*Expert Elite*
Alfred.NESWADBA
Posts: 9,099
Registered: ‎06-29-2007
Message 2 of 4 (276 Views)

Re: Casting DBobject to entity

11-20-2012 03:09 PM in reply to: insiaiftiqhar

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
-------------------------------------------------------------------------
Contributor
insiaiftiqhar
Posts: 19
Registered: ‎06-21-2012
Message 3 of 4 (271 Views)

Re: Casting DBobject to entity

11-20-2012 03:25 PM in reply to: Alfred.NESWADBA

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.

*Expert Elite*
Alfred.NESWADBA
Posts: 9,099
Registered: ‎06-29-2007
Message 4 of 4 (249 Views)

Re: Casting DBobject to entity

11-21-2012 12:11 AM in reply to: insiaiftiqhar

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
-------------------------------------------------------------------------
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.