Quantcast
Channel: Forums - ArcGIS for Desktop - General
Viewing all articles
Browse latest Browse all 2328

Arcmap new document event issue

$
0
0
Hello everyone,

I am adding a toolbox to arcmap 10.1.

public void Startup(ref object initializationData)
{
m_application = initializationData as IApplication;
if (m_application == null)
return;
if (m_application is IMxApplication)
{
IMxDocument pMxDoc;

// pMxDoc is ArcMap Map Document
pMxDoc = (IMxDocument)m_application.Document;
SetUpDocumentEvent((IDocument)pMxDoc);

}
StartupLicenseCheck(ref initializationData);
}

private void SetUpDocumentEvent(ESRI.ArcGIS.Framework.IDocument myDocument)
{
m_docEvents = myDocument as ESRI.ArcGIS.ArcMapUI.IDocumentEvents_Event;
m_docEvents.NewDocument += new ESRI.ArcGIS.ArcMapUI.IDocumentEvents_NewDocumentEventHandler(OnNewDocument);
m_docEvents.OpenDocument += new ESRI.ArcGIS.ArcMapUI.IDocumentEvents_OpenDocumentEventHandler(OnOpenDocument);
}


void OnNewDocument()
{
ESRI.ArcGIS.Framework.IDocument theDocument = m_docEvents as ESRI.ArcGIS.Framework.IDocument;
//TODO: Add your document handler event code

AddToolbox();
}

void OnOpenDocument()
{
ESRI.ArcGIS.Framework.IDocument theDocument = m_docEvents as ESRI.ArcGIS.Framework.IDocument;
//TODO: Add your document handler event code

AddToolbox();
}

private void AddToolbox()
{
// Load toolbox into ArcToolbox
IArcToolboxExtension arcTbxExt;
try
{
arcTbxExt = (IArcToolboxExtension)m_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
{
string Assembly_ToolBoxPath = (this.GetType().Assembly.Location).ToLower();
string Assembly_Name = this.GetType().Assembly.ManifestModule.ScopeName.ToLower();
Assembly_ToolBoxPath = Assembly_ToolBoxPath.Replace(Assembly_Name, "");
string strToolBoxPath = (Assembly_ToolBoxPath + "OxyImportExportGPTool").ToLower();

ToolboxWorkspaceFactory pToolboxWorkspaceFactory = new ToolboxWorkspaceFactory();
IToolboxWorkspace pToolboxWorkspace = (IToolboxWorkspace)pToolboxWorkspaceFactory.OpenFromFile(strToolBoxPath, 0);
IGPToolbox pToolbox = pToolboxWorkspace.OpenToolbox("OXY Tools.tbx");

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

This code works perfect for onOpenDocument event. But does not work for onNewDocument event.
I saw previous post about this issue back with 9.3 arcgis version but not answer about it.

Has this beed fixed? What is the work around here?

Any help will be well appreciated.

links relative to same problem;

http://forums.esri.com/Thread.asp?c=...37&mc=9#539150

http://forums.esri.com/Thread.asp?c=...3&mc=46#536337

http://forums.esri.com/Thread.asp?c=93&f=1728&t=179937

http://efreedom.com/Question/F-14401...-Toolbox-Issue

http://forums.esri.com/Thread.asp?c=93&f=993&t=176427


thanks a lot,


Otto Arturo

Viewing all articles
Browse latest Browse all 2328

Trending Articles