Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Revit and MVVM

retug_austin
Enthusiast

Revit and MVVM

retug_austin
Enthusiast
Enthusiast

New to programming in C# and the Revit API and I think implementing some MVVM will help solve a lot of the complications my programs are running into.

 

First basic question, would implementing a MVVM allow me to quickly see, say a list of beams in revit, and if the beam type names get updated in revit, the beam list would update dynamically?

 

See below in the gif, the current setup does not know that the initial selected types names changed, would an MVVM solution solve this?

 

Recording 2024-03-19 at 21.39.32.gif

Secondly, are there any good examples of Revit and MVVM? This is a sea of syntax I have not seen before, so some examples would be very helpful. I assume I could also follow any MVVM example and the lessons learned would still apply, but if there are good Revit examples, that would be helpful.

 

I have the non-working test code (shown in the .gif above) up on github:

https://github.com/retug/LearningCSharp/tree/main/MVVM

 

My Model - RevitFramingModel.cs

My ViewModel - MainViewModel.cs
My View - MainWindow.cs

 

Most of this was put together with chatgpt, but if you see any issues regarding the datagrid not dynamically updating with the updated Revit beam type names, I would appreciate the pointer.

 

Thanks!

0 Likes
Reply
1,076 Views
9 Replies
Replies (9)

scgq425
Advocate
Advocate

Dear retug_austin:

if u want learn more revit MVVM project , u can read the hermmy @jeremy_tammik and nice3point @nice3point 's github , the RevitLookUp , this is a great project to learn MVVM and Revit.

> [](https://github.com/jeremytammik/RevitLookup)

LanHui Xu 徐兰辉
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Blog
LinkedIn
Revit/CAD Development | Steel Product Manager

EESignature

retug_austin
Enthusiast
Enthusiast

@scgq425 Thanks for this, to my surprise, when using the revit lookup, snoop selection tool, it does not appear to be dynamic if the selected object has changed.

retug_austin_0-1710986424043.gif

Just so I'm clear, using something like MVVM would allow me to know that the element type and other parameters associated with the change have been updated, correct? 

0 Likes

scgq425
Advocate
Advocate

Dear retug_austin:

the first MVVM data use notfity implention to modify data , but in revit cant has this , so need to use some event to chang data to u data serives.

in lookup project , when user changed the element type . data cant trigged data, so u can add document type changed event , if u want to modify data ,u can monitor the type changed . use the  documentchanged to record and modify this data.

but if one element has more constraints , u need to create a function to clean the data , so if u wan to make up u idea u can use this event in MVVM.

LanHui Xu 徐兰辉
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Blog
LinkedIn
Revit/CAD Development | Steel Product Manager

EESignature

0 Likes

reylorente1
Collaborator
Collaborator

Hola,Aqui te comparto un ejemplo,de como usar MVVM en Revit.Es un ejemplo sencillo,espero que te sirva o te ayude.
El ejemplo consiste en seleccionar un elemento,y muestra el nombre y el ID en un TexBox(WPF) y tambien te permite borrarlo y volver a elegir otro elemento

 

Hello, Here I share an example of how to use MVVM in Revit. It is a simple example, I hope it is useful or helps you.
The example consists of selecting an element, and shows the name and ID in a TexBox (WPF)and also allows you to delete it and choose another element again.

0 Likes

aguterHFKHP
Contributor
Contributor

@reylorente1  Thanks for the file, any chance you upload the files outside of a .rar? Github or individual files? I'm not allowed to to interact with .rar files on the work computer. Our IT guy has been burned too many times.

0 Likes

reylorente1
Collaborator
Collaborator

Disculpa, no sé cómo guardar el archivo en el Git.... Tengo que aprenderlo. Pero si quieres, escríbeme tu email. y te lo reenvió.

 

Sorry, I don't know how to save the file in Git... I have to learn it. But if you want, write me your email. and forwarded it to you.

 

0 Likes

reylorente1
Collaborator
Collaborator

Revisa, mira ver si puedes abrirlo (Check to see if you can open it)

https://github.com/reylorente1/MVVM_Seleccion

0 Likes

retug_austin
Enthusiast
Enthusiast

@reylorente1 , thank you and welcome to github 🙂

I will review.

0 Likes