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)
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
If (fullEntPath.Length > 0) Then
was the 1st thing i tried before i came to this forum.
the if statement does run tho.
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
'...
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.
ooooh.. here is the culprit himself.
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.
-gile
the learner is learing at great pace. forgive his ignorance
btw - the trycast did not correct my problem
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.
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
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 ' ...
Can't find what you're looking for? Ask the community or share your knowledge.