IExtension and context menu

1813
7
07-21-2011 05:59 AM
ThibautDusanter
New Contributor
Hi,

I am currently developping an ArcMap extension. I am facing some problems regarding the sketch tool context menu:

when the extension is registered, the sketch tool context menu does not appear on right click.
The problem disapears when I remove the extension using the ArcGIS categories executable.

I Searched on the documentation but I did not find any topic related.
Does someone know about that? Do I have to do something when the event OnContextMenu is thrown?

Thanks a lot for your help
0 Kudos
7 Replies
ThibautDusanter
New Contributor
Hi again,

Nobody has an idea or a clue of the reason for this issue. I am really stuck...

Thanks
0 Kudos
NeilClemmons
Regular Contributor III
I'm not sure that you're correctly describing what you're doing.  An extension is a class that implements IExtension and is registered in the ESRI Mx Extensions component category.  An extension will not affect any tools, commands, toolbars, or menus unless you write code inside the class to specifically do that.

You mention OnContextMenu.  That is a method on the ITool interface.  If you are creating a class that implements ITool, then that is a tool not an extension.  You use OnContextMenu to provide the user with your own custom context menu for your tool.  If you do this, then you need to make sure this method returns a value of True (in addition to displaying your menu).  Otherwise, leave the method stub blank (or explicitly return a value of False) to leave the default context menu (if any) in place.

If you provide more information about what you're doing, someone might be able to help.  You might also want to post your code.
0 Kudos
ThibautDusanter
New Contributor
Thank you for your response

I am sorry for the unclear description, I will try to explain it better:

The problem is not coming from one of my Tool since I am using the basic Sketch Tool provided in ArcGIS.
The thing is, when I register my extension using "MxExtension.Register(regKey)", the same Sketch Tool does not display its context menu on a right click. If I comment out the registration line ("MxExtension.Register(regKey)"), I am able to display the context menu again. That's why I was thinking that I have to do something in my extension...

I hope it´s clearer now and that someone has an idea.

Thanks again
0 Kudos
ThibautDusanter
New Contributor
Hi again,

I have isolated the reason for the issue. It comes from the connexion with the document events.
If I comment out all the AddHandler lines in the following code, the context menu is displayed again. Does someone see what I am doing wrong?

Thanks a lot

    Public Overridable Sub Startup(ByRef initializationData As Object) Implements IExtension.Startup
        ' this section provides a hook into the application framework
        If Not initializationData Is Nothing Then
            ' Get the application
            m_application = CType(initializationData, IApplication)

            ' Link the document events
            m_documentEvents = CType(m_application.Document, IDocumentEvents_Event)
            AddHandler m_documentEvents.OpenDocument, AddressOf Me.m_documentEvents_OpenDocument
            AddHandler m_documentEvents.NewDocument, AddressOf Me.m_documentEvents_NewDocument
            AddHandler m_documentEvents.CloseDocument, AddressOf Me.m_documentEvents_CloseDocument
            AddHandler m_documentEvents.BeforeCloseDocument, AddressOf Me.m_documentEvents_BeforeCloseDocument
            AddHandler m_documentEvents.ActiveViewChanged, AddressOf Me.m_documentEvents_ActiveViewChanged
0 Kudos
ThibautDusanter
New Contributor
It seems to be a known issue...
http://gis.stackexchange.com/questions/7084/using-idocumentevents-event-from-a-net-4-assembly-within...

I will keep you informed if I find a solution!
0 Kudos
ThibautDusanter
New Contributor
At the end, I chose to use the framework 3.5 and it's working.
0 Kudos
GangYang
New Contributor
At the end, I chose to use the framework 3.5 and it's working.


Your post saved me at least one whole day. Thank you! With ArcGIS 10.0 this issue remains. With 10.1 it's ok with framework 4.0
0 Kudos