I have a situation where a form is raising an External Event and then an External Event Handler is making some changes to the Revit model.
The form is basically a list of rooms in the model and when the user makes a selection then the room object is changed.
My question is: how can the form then be updated with the changes to the room? I can't see anyway for the External Event handler to 'talk' back to the form.
Solved! Go to Solution.
Solved by jeremytammik. Go to Solution.
Dear Sean,
Thank you for your query.
There are many possible solutions for this, and they completely independent of the Revit API.
In your external event Execute method, you have access to a valid Revit API context and can query and modify the BIM as you please.
From that context, you can use any kind of inter-process communication you like to transport any information you like back to your modeless form.
Actually, since the modeless form can be managed by the same process as the external event, there is no need for inter-process at all, you are in the same process.
For instance, your modeless form can implement some public methods that can be called from within the external event Execute method to talk back to it.
I hope this helps.
Best regards,
Jeremy
Hi Jeremy,
Thanks for the reply. Yes I realized after I posted this that it isn't really a Revit API problem.
Because the form and the external event handler are both instantiated in the same external command it was a simple case of adding a reference to the form to my event handler.
Thanks,
Sean
Sean,
Care to share a small sample of how you did this? I think I am running into the same issue, and this would help.
Thanks!
Of course.
The Execute method of my external command looks like this:
public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elemSet) { var handler = new RequestHandler(); var exEvent = ExternalEvent.Create(handler); // This is the view model that is bound to the WPF window var viewModel = new ViewModel(cmdData.Application.ActiveUIDocument); // This is the important bit - add a reference to the view model to the reqeust handler handler.VM = viewModel; // Instantiate the WPF window, pass the external event and handler and also bind to the view model var window = new ViewWindow(exEvent, handler) { DataContext = viewModel }; window.Show(); return Result.Succeeded; }
Then in the Execute method of my event handler I call a public method on my view model (which updates the window):
VM.UpdateSelectedRoom();
Its not super elegant but it seems to work ok.
Hi,
Thanx I did the same thing with a winform, I added myForm to the ExtEvent handler, so far it has worked well, I can now use multiple buttons and refresh and keep the form alive whilst the user edits the model in between transactions initiated from the external event!
// We give the objects to the new dialog;
// The dialog becomes the owner responsible for disposing them, eventually.
m_MyForm = new Fam_DGV_Form(uiapp, exEvent, handler);
//Add the form to the handler, so that the form can be updated from the externalEvent class(the handler)
handler.FormThing = m_MyForm;
m_MyForm.Show();
Hello,
I am very interested in how the handler references the windows form. Is there anyway I can see the ExternalEventHandler code portion to understand this line:
handler.FormThing = m_MyForm;
I am struggling to communicate with an externaleventhandler and a windows form and I believe this is the solution.
Thanks,
Norm
Dear Norm,
Thank you for your query.
Yes, the window handle is an important identifier.
For a full-blown IPC sample, you can also take a look at this recent sample:
Though, in general, you should not need that, since your external event handler and Windows form can Norm-ally both easily live together in the same process, in the same add-in, together with Revit itself.
I hope this helps.
Best regards,
Jeremy