Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have an extension class in an ArcMap addin project of which loads a custom toolbox into ArcToolbox when the user opens ArcMap or opens a previously created map. My toolbox gets added to ArcToolbox fine except when the user creates a new map from File > New. My toolbox just disappears (no messages). I'm running AG10 SP2 but it doesn't work in AG10 base either.

Anyone else experience this? Solutions?

protected override void OnStartUp()
{
   AddToolboxes();
   #region Wire events
   ArcMap.Events.NewDocument += delegate() { ArcMap_NewDocument(); };
   #endregion
}
void ArcMap_NewDocument()
{
   AddToolboxes();
}
void AddToolboxes()
    {

        // Load toolbox into ArcToolbox
        IArcToolboxExtension arcTbxExt;
        try
        {
            arcTbxExt = (IArcToolboxExtension)ArcMap.Application.FindExtensionByName("ESRI ArcToolbox");
            if (arcTbxExt == null) { throw new Exception("ArcToolbox extension could not be found."); }
        }
        catch (Exception ex)
        {
            System.Windows.Forms.MessageBox.Show("Error finding ArcToolbox extension." + Environment.NewLine + " - " + ex.Message);
            return;
        }

        try
        {
            IGPToolbox2 toolbox = Maersk.Functions.Toolbox.OpenToolbox("C:\\Toolboxes\\MyToolbox.tbx");
            arcTbxExt.ArcToolbox.AddToolbox((IGPToolbox)toolbox);
            arcTbxExt.ArcToolbox.Refresh();

        }
        catch (Exception ex)
        {
            System.Windows.Forms.MessageBox.Show("Error launching  toolbox." + Environment.NewLine + " - " + ex.Message);
            return;
        }

    }
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

There's something flaky going on here.

With the add-in extension below, a messagebox comes up showing me my toolbox is there. It works fine the first time the doc loads, but if I hit the new Map File button the messagebox will come up, then a few seconds later the toolbox disappears. Something is clearing the toolboxes after the maps changed event fires.

enter image description here

private IGeoProcessor2 m_Geoproc;
protected override void OnStartup()
{
    ArcMap.Events.MapsChanged += new ESRI.ArcGIS.ArcMapUI.IDocumentEvents_MapsChangedEventHandler(Events_MapsChanged);
    m_Geoproc = new GeoProcessorClass();
}

void Events_MapsChanged()
{
    if(string.IsNullOrEmpty(m_Geoproc.ListToolboxes("testtoolbox").Next()))
    {
        m_Geoproc.AddToolbox(@"D:\gems\MMS\testtoolbox.tbx");
        MessageBox.Show("added toolbox");
    }
}
share|improve this answer
    
Yup that was exactly what I got. I thought I was going mad so perhaps not. Looks like a bug. –  Rob Sep 8 '11 at 13:26
    
It would be rather hacky, but I guess you could put a background thread on your extension with a timer that periodically checks to see if your toolbox is there, and if not add it. –  Kirk Kuykendall Sep 8 '11 at 14:30
    
True - that's one way. I'll submit to Esri as a bug anyway. Thanks for your input –  Rob Sep 13 '11 at 9:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.