jeremytammik / RevitLookup

Interactive Revit RFA and RVT project database exploration tool to view and navigate BIM element parameters, properties and relationships.
http://thebuildingcoder.typepad.com
MIT License
1.03k stars 294 forks source link

Revit Document isReadOnly = true when dashborad shows up #206

Closed duchangyu closed 3 months ago

duchangyu commented 3 months ago

Hi there,

I am trying to take advantage of RevitLookup project as a starting template for new plugin, which is a good start with basic features such as modern UI, settings , update checking, etc. Which is great! :)

But I get a problem when trying to add my customer features. I found the RevitAPI.Document.isReadOnly = true when the form shows up, so I cannot manipulate the revit document in following steps. image

image

Exception:

Autodesk.Revit.Exceptions.InvalidOperationException:“The document is currently in read-only state. EditFamily may not be executed.”

As it shows in the breakpoint.

To reproduce, in \ViewModels\Pages\DashboardViewModel.cs, add following code:

 if (!Validate()) return;

 //  actually I will put following code in a service, and call it from viewModel, but 
 // for testing, I make the business logic code simple and put it below 
 // check whether the  document is readonly or not
 bool docRO = RevitApi.Document.IsReadOnly;
 Document  doc = RevitApi.Document;

 // keep manipulate the document
 // for example, open a family and get parameters
 // Create a new document
 FilteredElementCollector collector = new FilteredElementCollector(doc).OfClass(typeof(Family));

 foreach (Family family in collector)
 {

     if (family.IsEditable)
     {
         try
         {
             Document familyDocument = doc.EditFamily(family); // exceptions here due to Document Readonly

             // get family parameters 
             // ... 
         }
         catch (Exception ex)
         {
             //
             notificationService.ShowError("Exception",ex.Message);
         }

     }
 }

Any idea?

PS: But if I keep going and check the Document status in revitLookup, and it says isReadOnly is false again. image

Would you please help to explain what's happening under the hood, and what is the correct way to add custom features to manipulate the revit Document?

Nice3point commented 3 months ago

Dashboards is running in another thread, revit blocking this executions. Please use external handlers https://github.com/Nice3point/RevitToolkit?tab=readme-ov-file#external-events

duchangyu commented 3 months ago

Thank you, it helps!