Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Updating a form from an ExternalEvent handler

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
sean_dodsworth
2359 Views, 8 Replies

Updating a form from an ExternalEvent handler

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.

8 REPLIES 8
Message 2 of 9

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



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 9

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

Message 4 of 9
Anonymous
in reply to: sean_dodsworth

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! 

Message 5 of 9
sean_dodsworth
in reply to: Anonymous

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.

 

Message 6 of 9
Anonymous
in reply to: sean_dodsworth

Sean,

 

This makes sense now. Thank you! 

Message 7 of 9

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();

Message 8 of 9
Anonymous
in reply to: n_mulconray

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

Message 9 of 9
jeremytammik
in reply to: Anonymous

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:

 

https://thebuildingcoder.typepad.com/blog/2019/04/set-floor-level-and-use-ipc-for-disentanglement.ht...

 

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

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Customer Advisory Groups


Rail Community