Implied selection problem

Implied selection problem

Anonymous
Not applicable
1,118 Views
2 Replies
Message 1 of 3

Implied selection problem

Anonymous
Not applicable

I have a problem when i try to run a commend called by a FeatureUpdated event, i try to select the implied selected feature using this code :

 

 Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor


 

Dim result As PromptSelectionResult = ed.SelectImplied()
        If result.Status <> PromptStatus.OK Then Exit Sub
        Dim MgSelBase As  MgSelectionBase = AcMapFeatureEntityService.GetSelection(result.Value)
        Dim Mglayers As MgReadOnlyLayerCollection = MgSelBase.GetLayers()
         Dim layerBase As MgLayerBase = MgSelBase.GetLayers(0)

Dim featReader As MgFeatureReader = MgSelBase.GetSelectedFeatures(layerBase, layerBase.FeatureClassName, False)

      While featReader.ReadNext
       
 ' operations

         End While
This code makes autocad crash
the same thing hapen when it's used by a user selection(ed.GetSelection(entOptions)) instead of an event
Has anyone encountered the same problem ?

 

0 Likes
1,119 Views
2 Replies
Replies (2)
Message 2 of 3

norman.yuan
Mentor
Mentor

1. Does your command method have CommandFlags.UserPickSet flag set?

 

2. Have you debugged the code so that you knowwhich line of code is the offending one? That is, does AutoCAD Map pass through this line:

 

 If result.Status <> PromptStatus.OK Then Exit Sub

 

If yes, then I think you need to test if the SelectionSet.Count>0 or not:

 

If result.Value.Count=0 Then Exit Sub

 

because if the count is 0, the next line of code would not get you a MgSelectionBase object.

 

Anyway, simply place a break point and then step through the code would allow you easily find the cause of crash.

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 3

Anonymous
Not applicable

Thank you for the reply

 

I have tried with and without CommandFlags.UserPickSet flag set, but there is the same result, Autocad crash when i try to get the layer of the MgSelBase. This is perhaps because i use this code with an event handler and when there are features checked out on the map, but i don't know.

 

I found another way to achieve what i wanted to do, i use the FeatureEventArgs of the eventhandler to identify the feature updated, instead of SelectImplied()

 

Handler added at the initialisation of the dll :

Dim fs As AcMapFeatureService = AcMapServiceFactory.GetService(MgServiceType.FeatureService)

        AddHandler fs.FeatureUpdated, AddressOf fs_FeatureUpdated

 

Function called when a modified feature is checked in :

Sub fs_FeatureUpdated(ByVal sender As Object, ByVal e As AcMapFeatureEventArgs)

        Dim feat As AcMapFeature = e.GetFeature()
 ' operations
End sub

 

0 Likes