.NET training labs

.NET training labs

Anonymous
Not applicable
1,352 Views
12 Replies
Message 1 of 13

.NET training labs

Anonymous
Not applicable

hey all.  i'll be frequenting regularly this forum from now on. asking all kinds of dumb questions.

 

like:

who made the these training labs?  http://images.autodesk.com/adsk/files/autocad_net_training0.zip

 

im having trouble with lab6

an editor.PointMonitor event triggers this sub routine called myPointMonitor

 -the lab then declare a FullSubentityPath variable = e.Context.GetPickedEntities()

 and checks IF (fullEntPath.Length) Then  

 

should their not be an argument here?

 

i get " out of bound of array " here.   and the IF statement is never executed.

 

if anyone can assist id appreciate it.

bare in mind i'm new to the autocad api  and have only indermediate exprience with vb.net

 

 

edit: sry   the IF is executed  but encounters the exception @

Dim ent As Curve = trans.GetObject(fullEntPath(0).GetObjectIds(0), OpenMode.ForRead)

 

 

0 Likes
1,353 Views
12 Replies
Replies (12)
Message 2 of 13

_gile
Consultant
Consultant

Hi,

 

Try to replace Curve with Entity:

 

Dim ent As Entity = trans.GetObject(fullEntPath(0).GetObjectIds(0), OpenMode.ForRead)



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 13

Anonymous
Not applicable

it seems that was not the intention because further

 

 Dim pnt As Point3d = ent.GetPointAtDist(myTypedVal.Value)

GetPointAtDist is not a member of entity

 

open lab6 and run debug.. check it out , its a small download

0 Likes
Message 4 of 13

_gile
Consultant
Consultant
If (fullEntPath.Length) Then

This won't work with C# or (I think) VB with Option Strict On.

 

Try:

If (fullEntPath.Length > 0) Then


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 5 of 13

Anonymous
Not applicable
If (fullEntPath.Length > 0) Then

was the 1st thing i tried before i came to this forum.

 

the if statement does run tho.

0 Likes
Message 6 of 13

_gile
Consultant
Consultant

Ok, I downloaded the lab and looked up into the code.

I do not know if it's your problem but an exception will occur with the "newInput" command if the cursor comes near an entity which is not a curve.

The "MyInputMonitor" code would check if the entity is a curve. Here's a way (not certain about the VB syntax):

 

replace:

' open the Entity for read, it must be derived from 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
'...

with

' open the Entity for read, try to cast it as Curve
Dim ent As Curve = TryCast(trans.GetObject(fullEntPath(0).GetObjectIds()(0), OpenMode.ForRead), Curve)
' ok, so if we are over something - then check to see if it is a curve and if it has an extension dictionary
If ent IsNot Nothing AndAlso ent.ExtensionDictionary.IsValid Then
'...

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 7 of 13

StephenPreston
Alumni
Alumni

Oops. That would be a bug. I'll have someone update the labs with the corrected code. Sorry for the inconvenience and thanks for reporting it.

Cheers,

Stephen Preston
Autodesk Developer Network
0 Likes
Message 8 of 13

_gile
Consultant
Consultant

Hi Stephen,

 

There's the same 'bug' in the C# code.

 

PS: IMO, arriving to this step in the training (using event handlers) it can be assumed that the learner should know enough about debugging and type casting to correct this by himself...



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 9 of 13

Anonymous
Not applicable

ooooh..  here is the culprit himself.  Cat Tongue

kudoos on making the labs , i find it very useful to fasttrack my learning. the power point is also very helpful.

 

now that i have your attention i'd like to pick your brains about dictionaries:

Can you give me a simple senario where saving data to dictionaries is useful / like what kind of data?

i reckon i can store any nessary data i need within variable memory in run time.

\\ saving data to entities seems very much like an GIS application. i rekon i can expose the dictionary in an interface to allow users to append data to entities and make autcad behave like gis software

 

hey thx _gile for taking a look.

 

 

0 Likes
Message 10 of 13

Anonymous
Not applicable

-gile

 

the learner is learing at great pace.  forgive his ignorance

 

btw - the trycast did not correct my problem

0 Likes
Message 11 of 13

_gile
Consultant
Consultant

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
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 12 of 13

Anonymous
Not applicable

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

0 Likes
Message 13 of 13

_gile
Consultant
Consultant

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
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes