need help debugging code

need help debugging code

Anonymous
Not applicable
422 Views
1 Reply
Message 1 of 2

need help debugging code

Anonymous
Not applicable
Hi. I need help here. There is an error in my code when I run the program in autocad. Im using vb.net. The line where the error is in denoted by <----. Error is Object reference not set to an instance of an object.

Dim myDWG As ApplicationServices.Document
Dim myDB As DatabaseServices.Database
Dim myEd As EditorInput.Editor
Dim myPSR As EditorInput.PromptSelectionResult
Dim mySS As EditorInput.SelectionSet
Dim myFilter(0) As DatabaseServices.TypedValue
Dim myObjIds As DatabaseServices.ObjectIdCollection
Dim myObjId As DatabaseServices.ObjectId
Dim myEnt As DatabaseServices.Entity
myFilter(0) = New DatabaseServices.TypedValue(DatabaseServices.DxfCode.BlockName, "aaa")
Dim mySF As New EditorInput.SelectionFilter(myFilter)
Dim maxPt As Geometry.Point3d
Dim minPt As Geometry.Point3d
Dim dist As Double
myDWG = ApplicationServices.Application.DocumentManager.MdiActiveDocument
myDB = myDWG.Database
myEd = myDWG.Editor
myPSR = myEd.SelectAll(mySF)
If Not IsNothing(myPSR.Value) Then
mySS = myPSR.Value
myObjIds = New DatabaseServices.ObjectIdCollection(mySS.GetObjectIds)
For Each myObjId In myObjIds
myEnt = myObjId.GetObject(DatabaseServices.OpenMode.ForRead) <------ error here
Next
End If

Edited by: a7v1n on Apr 6, 2010 8:19 PM
0 Likes
423 Views
1 Reply
Reply (1)
Message 2 of 2

norman.yuan
Mentor
Mentor
Firstly, do not use

If Not IsNothing(myPSR.Value) Then
...
End If

to test if the PromptSelectionresult is OK or not. Editor.SelectAll() always returns a non-null PromptSelectionResult object, so your IsNothing() test is useless. Instead, you should examine PromptSelectionResult.Status property to see if the SelecAll() method grabs something or not.

Secondly, you need to place GetObject() within a scope of transaction.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes