WPF UI Control Updating Model Live? (w/o closing dialog window)

Good afternoon,

I’m new to creating UI using WPF. I’m wondering if the slider (or other controls) on a WPF UI can update the model live in the same way that Dynamo’s geometry can be seen through it’s preview feature.

For example, controlling a lines length in Dynamo with a slider you will see a preview in the model update live if you are on automatic mode.

I attempted to recreate this same behavior by creating a model curve when the value of the slider is changed as seen below:

This did not produce the result I was looking for as the model only updates after the dialog has closed.

So, is there any way to update the model with WPF controls in the same way Dynamo’s geometry preview works on automatic mode?

Thanks!

1 Like

Sadly i dont think you can as the WPF windows is running STA(any developer can prove me otherwise?) You will need to use it as explicit node, i believe it will update automatically

1 Like

So first thing that I would say is yes, you can do that, but I don’t think it’s a question to be asked on a Dynamo Forum. It has really nothing to do with Dynamo. My understanding of your question is that it is not a Dynamo node that you are trying to build (because you can already do what you want in Dynamo), but rather a typical Revit plugin with a WPF UI. In that case, you can look into something called External Event for Revit. What is external event?

Let me explain first how Revit works. Revit is a single threaded application. That means that for the most part when you create a button on a ribbon to do something custom, you define it as an ExternalCommand. It executes on the same thread as the main Revit process. What that means, is that when a windows is shown, Revit window becomes inactive, and you can’t interact with it. Your code would execute, window would get closed, and then control is returned to Revit.

What you want to do, in order to be able to change a slider, and see that drive some curve in Revit is create a so called External Event driven command. It’s a type of interaction mode where UI is on its own UI thread, and doesn’t lock Revit UI up, so you can interact with both at the same time. You can do it in two ways, one is using an IdlingEvent and another using an ExternalEvent. Dynamo uses the IdlingEvent method for its execution, and that’s why you can see that when you drag a slider in Dynamo it moves something in Revit “live”.

Again, you will need to go read up about External Events or Idling Events in Revit.

Cheers!

-K

7 Likes

Good info about external Events here.
https://forums.autodesk.com/t5/revit-api-forum/externalevent/m-p/9056391#M41576

1 Like