AutoCAD Map 3D Developer
Welcome to Autodesk’s AutoCAD Map 3D Developer Forums. Share your knowledge, ask questions, and explore popular AutoCAD Map 3D Developer topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Implied selection problem

2 REPLIES 2
Reply
Message 1 of 3
olivierguy
815 Views, 2 Replies

Implied selection problem

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 ?

 

2 REPLIES 2
Message 2 of 3
norman.yuan
in reply to: olivierguy

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

Message 3 of 3
olivierguy
in reply to: norman.yuan

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

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost