.NET

Reply
*Expert Elite*
_gile
Posts: 2,077
Registered: ‎04-29-2006
Message 11 of 13 (112 Views)

Re : .NET training labs

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

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
Contributor
theEntity
Posts: 21
Registered: ‎08-05-2012
Message 12 of 13 (109 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

 

regards

*Expert Elite*
_gile
Posts: 2,077
Registered: ‎04-29-2006
Message 13 of 13 (94 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
            Try

                ' 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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community