Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
Based on the Sdk sample called "ModelessForm_ExternalEvent", I run a modeless form to do some stuff
I'd like to close my modeless form when all documents are closed.
I've tried to do this but it seems that when I'm opening more than 2 documents, DoCumentClosed events do not raise.
What's wrong with my code please?
public class Main : IExternalApplication
{
// class instance
internal static Main thisApp = null;
// ModelessForm instance
private RoutingManagerModelessForm m_RoutingManagerForm;
public static Application m_App;
#region external application public methods
/// <summary>
/// Called when Revit starts up
/// </summary>
/// <param name="application"></param>
/// <returns></returns>
/// <exception cref="System.NotImplementedException"></exception>
public Result OnStartup(UIControlledApplication application)
{
// Initialize whole plugin's user interface.
var ui = new SetupInterface();
ui.Initialize(application);
thisApp = this;
m_RoutingManagerForm = null;
return Result.Succeeded;
}
#endregion
/// <summary>
/// Called when Revit shutdown
/// </summary>
/// <param name="application"></param>
/// <returns></returns>
/// <exception cref="System.NotImplementedException"></exception>
public Result OnShutdown(UIControlledApplication application)
{
if (m_RoutingManagerForm !=null && m_RoutingManagerForm.IsVisible)
{
m_RoutingManagerForm.Close();
}
return Result.Succeeded;
}
#region private methods
/// <summary>
/// This method creates and shows a modeless dialog, unless it already exists.
/// </summary>
/// <remarks>
/// The external command invokes this on the end-user's request
/// </remarks>
///
public void ShowForm(ExternalCommandData cD)
{
ExternalCommandData commandData = cD;
m_App = cD.Application.Application;
try
{
// If we do not have a dialog yet, create and show it
if (m_RoutingManagerForm == null || WindowHelper.IsDisposed(m_RoutingManagerForm))
{
// We give the objects to the new dialog;
// The dialog becomes the owner responsible fore disposing them, eventually.
m_RoutingManagerForm = new RoutingManagerModelessForm(commandData);
m_RoutingManagerForm.myThisApp = this;
m_RoutingManagerForm.Show();
m_App.DocumentClosed += new EventHandler<DocumentClosedEventArgs>(OnDocumentClosed);
}
}
#region catch and finally
catch (Exception ex)
{
ess_routing.Log.WriteDebug("EE_UpdateForm_ViewActivatedMethod" + Environment.NewLine + ex.Message + Environment.NewLine + ex.InnerException, true);
}
finally
{
}
#endregion
}
private void OnDocumentClosed(object sender, DocumentClosedEventArgs e)
{
System.Windows.Forms.MessageBox.Show("Documents en cours:" + m_App.Documents.Size);
if (m_RoutingManagerForm != null)
{
m_RoutingManagerForm.WakeUp();
if (m_App.Documents.Size == 0)
m_RoutingManagerForm.Close();
m_App.DocumentClosed -= new EventHandler<DocumentClosedEventArgs>(OnDocumentClosed);
}
}
Pierre NAVARRA
SONA-Architecture.
http://www.sona-architecture.com
https://fr.linkedin.com/in/pierre-navarra-62032a107
SONA-Architecture.
http://www.sona-architecture.com
https://fr.linkedin.com/in/pierre-navarra-62032a107
Solved! Go to Solution.