Friday, February 24, 2017

Export All Possible Revit Warnings

A few weeks ago, Konrad Sobon, posted a Python script for exporting all the possible Revit warnings to use in a Dynamo script that analyzes and ranks the warnings in the current model. Since I mostly work in C#, I took his Python script and created a C# macro. I've had several requests for it, so here it is...


public void ExportWarnings()
{
    try
    {
        using (StreamWriter writer = new StreamWriter(@"C:\temp\warnings.txt"))
        {
            FailureDefinitionRegistry failures = Autodesk.Revit.ApplicationServices.Application.GetFailureDefinitionRegistry();
            IList<FailureDefinitionAccessor> failuresList = failures.ListAllFailureDefinitions();
            
            foreach (FailureDefinitionAccessor failure in failuresList)
            {
                if (failure.GetSeverity() == FailureSeverity.Warning)
                    writer.WriteLine(failure.GetDescriptionText());
            }
            
            writer.Close();
        }
    }
    catch
    {
        
    }
    
}


And the resulting file from Revit 2017 : Warnings.txt

Wednesday, February 01, 2017

Adding Revisions to a Sheet Index

Recently, I had someone make a request for adding an X to a column in a sheet index schedule for all the revisions that sheet had. Currently, they have to do it by hand and it is tedious.





















To get this to work, I added a parameter for each revision called "Seq #" (with # being the revision sequence number). I looped through each revision on each sheet and looked up it's sequence number, then add an X to the parameter matching it.

Here is a video showing how it fills in the sheet index schedule:






And the code...


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
public void SheetRevisions()
{
 Document doc = this.ActiveUIDocument.Document;
 
 using (Transaction t = new Transaction(doc, "Revisions on Sheet"))
 {
  t.Start();
  
  // loop through all the sheets in the model
  foreach (ViewSheet vs in new FilteredElementCollector(doc).OfClass(typeof(ViewSheet)))
  {
   // get a list of all the Revision Ids for this sheet
   IList<ElementId> revIds = vs.GetAllRevisionIds();
   
   // if at least 1 Revision, continue
   if (revIds.Count > 0)
   {
    // loop through each of the Revision Ids
    foreach (ElementId eid in revIds)
    {
     // get the actual Revision element
     Element elem = doc.GetElement(eid);
     Revision rev = elem as Revision;
     
     // add an X to the parameter named "Seq #"
     vs.LookupParameter("Seq " + rev.SequenceNumber.ToString()).Set("X");
    }
    
   }
  }
  
  t.Commit();
 }   
}