.NET

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

Casting DBobject to entity

298 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,417
Registered: ‎06-29-2007
Message 2 of 4 (291 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 (286 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,417
Registered: ‎06-29-2007
Message 4 of 4 (264 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
-------------------------------------------------------------------------
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!