Message 1 of 7

Not applicable
03-28-2020
04:20 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Dear
I created a modeless form because I need to select elements from Revit window and update the form repeatedly. but unfortunately, the dialog is not updated after the external event handler is called. It should be noted that I do no change the model in Revit, in fact, I just want to select elements and assign them into a node of a tree view. but the tree view is crashed after I click buttons in the form.
Best Regards
My Application.cs is as follows
public class Application : IExternalApplication
{
// class instance
internal static Application thisApp = null;
//ModelessForm instance
public static ModelessForm m_MyForm;
/// <summary>
/// Implements the OnShutdown event
/// </summary>
/// <param name="application"></param>
/// <returns></returns>
///
public Result OnShutdown(UIControlledApplication application)
{
if (m_MyForm != null && m_MyForm.Visible)
{
m_MyForm.Close();
}
return Result.Succeeded;
}
/// <summary>
/// Implements the OnStartup event
/// </summary>
/// <param name="application"></param>
/// <returns></returns>
///
public Result OnStartup(UIControlledApplication application)
{
m_MyForm = null; // no dialog needed yet;the command will bring it
thisApp = this; // static access to this application instance
return Result.Succeeded;
}
/// <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(UIApplication uiapp)
{
// If we do not have a dialog yet, create and show it
if (m_MyForm == null || m_MyForm.IsDisposed)
{
// A new handler to handle request posting by dialog
RequestHandler handler = new RequestHandler();
// External Event for the dialog to use (to post request)
ExternalEvent exEvent = ExternalEvent.Create(handler);
// We give the objects to the new dialog;
// The dialog becomes the owner responsible fore disposing them, eventually.
m_MyForm = new ModelessForm(exEvent, handler, uiapp);
m_MyForm.ExEvent = exEvent;
handler.Item = m_MyForm;
m_MyForm.Show();
}
}
And the execute of the external event is as follows:
public void Execute(UIApplication uiapp)
{
if ((Request.Take()) == RequestId.None)
{
UIDocument revitDoc = uiapp.ActiveUIDocument;
Document dbdoc = revitDoc.Document;
Autodesk.Revit.DB.View view = dbdoc.ActiveView;
ICollection<ElementId> ids = uiapp.ActiveUIDocument.Selection.GetElementIds();
if (0 == ids.Count)
{
FilteredElementCollector collector =
new FilteredElementCollector(revitDoc.Document, view.Id)
.WhereElementIsNotElementType();
ids = collector.ToElementIds();
}
ICollection<Element> elemSet = new
List<Element>(ids.Select<ElementId, Element>(id => dbdoc.GetElement(id)));
using (Transaction trans = new Transaction(uiapp.ActiveUIDocument.Document))
{
trans.Start("R2019 External Event Sample");
Item.ViewModelNonStatic(uiapp);
trans.Commit();
}
}
}
ViewModelNonStatic is a method of ModelessForm.
Solved! Go to Solution.