*Expert Elite*
Posts: 2,114
Registered: ‎04-29-2006
Message 11 of 13 (118 Views)

Re : .NET training labs

08-06-2012 12:14 PM in reply to: theEntity



Sorry if I offend you, this was not at all my intention (appologies for my poor English too).


The TryCast() method try to cast the DBObject returned by GetObject() in the specified type (Curve) and returns Nothing if the cast fails.

Then this is checked with the "IsNot Nothing" expression:

If ent IsNot Nothing AndAlso ent.ExtensionDictionary.IsValid Then

This works fine for me and correct the 'bug' I reported. 

If you still have a problem, please tell how it occurs (which command is running and what you're doing in the autoCAD Editor) and which code line fires the exception.


About Dictionaries, they're usefull to store data within the Database (NOD children) or within a DBObject (extension dictionaries). These data will be available after closing and re-opening the drawing.

Gilles Chanteau
Posts: 21
Registered: ‎08-05-2012
Message 12 of 13 (115 Views)

Re : .NET training labs

08-06-2012 12:33 PM in reply to: _gile

yes thanks _gile   . no offence taken

i learn myself and have only the forum to help if i get stuck.  i understand casting but the solution is more apparent for you because you have lots of experience


i made the change you suggest and it seems to validate correctly now..

much thx



*Expert Elite*
Posts: 2,114
Registered: ‎04-29-2006
Message 13 of 13 (100 Views)

Re : .NET training labs

08-06-2012 01:41 PM in reply to: theEntity

Another way (cheaper because the entity type is checked befor opening it) is to use the ObjectId.ObjectClass property:


    Public Sub MyInputMonitor(ByVal sender As Object, ByVal e As PointMonitorEventArgs)

        ' first lets check what is under the Cursor
        Dim fullEntPath() As FullSubentityPath = e.Context.GetPickedEntities()
        ' create a RXClass instance for the Curve class
        Dim curveClass As RXClass = RXClass.GetClass(GetType(Curve))
        ' check if there's something under the cursor and if it's derived from Curve
        If fullEntPath.Length > 0 AndAlso _
            fullEntPath(0).GetObjectIds(0).ObjectClass.IsDerivedFrom(curveClass) Then

            ' start a transaction
            Dim trans As Transaction = Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction

                ' open the Entity for read, we  already know it's a Curve
                Dim ent As Curve = trans.GetObject(fullEntPath(0).GetObjectIds(0), OpenMode.ForRead)

                ' ok, so if we are over something - then check to see if it has an extension dictionary
                If (ent.ExtensionDictionary.IsValid) Then

                    ' ...



Gilles Chanteau
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
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!