Thursday, April 13, 2017

Revit 2018 Export Warnings from Model to Excel

Revit 2018 has added a great new addition to the API that allows you to collect all of the Warnings that exist in the model. Previously, you could only export this list by using the builtin "Export" button in the Warnings dialog, that exported to a HTML file.

The new addition is the following:

IList<FailureMessage> warnings = doc.GetWarnings();

The following macro will export all the warnings in your model to Excel:

public void ExportWarningsToExcel()
{
 // make sure to add a reference to Excel Object Library
 // put the following (minus the // into your using statements)
 // using xls = Microsoft.Office.Interop.Excel;
 // using System.Reflection;
 
 // create a new Excel connection
 xls.Application xlApp = new xls.Application();   
 
 // make sure you have access to Excel
 if (null == xlApp)
 {
  TaskDialog.Show("Error", "Failed to start or access Excel");
  
  return;
 }
 
 // get the current model
 Document doc = this.ActiveUIDocument.Document;
 
 // get a list of all the model's warnings
 IList<FailureMessage> warnings = doc.GetWarnings();
 
 try
 {
  // show the Excel window
  xlApp.Visible = true;
  
  // create a new Workbook in Excel
  xls.Workbook workbook = xlApp.Workbooks.Add(Missing.Value);
  
  // create a new Worksheet in Excel
  xls.Worksheet worksheet = (xls.Worksheet)workbook.Worksheets.Item[1];
  
  // name the Worksheet with the model name
  worksheet.Name = doc.Title;
      
  // create a header row
  worksheet.Cells[1,1] = "Warning Description";
  worksheet.Cells[1,2] = "Elements";
  
  // count the number of warnings
  int numWarnings = 0;
  // start on row 2 for warnings
  int row = 2;
  
  // loop through each warning
  foreach (FailureMessage fmsg in warnings)
  {
   // add the warning desciption to cell in Excel
   worksheet.Cells[row, 1] = fmsg.GetDescriptionText();
   
   // create a string to hold element info
   string elements = "";
        
   // loop through the element ids
   foreach (ElementId eid in fmsg.GetFailingElements())
   {
    // get the element
    Element e = doc.GetElement(eid);
    
    // add the element category
    elements += e.Category.Name + " : ";

    // some elements fail when getting their family type, so skip getting type if it fails
    try
    {
     // get the element family type
     elements += e.LookupParameter("Family").AsValueString() + " : ";
    }
    catch
    {
     
    }
          
    // add the element name
    elements += e.Name + " : ";
    
    // add the element id
    elements += "id " + eid.ToString() + System.Environment.NewLine + System.Environment.NewLine;
   }
   
   // add elements to cell in Excel
   worksheet.Cells[row, 2] = elements;
   
   // go to next row to Excel
   ++row;
   
   // increment number of warnings
   numWarnings++;
  }
  // expand columns to fit text
  xls.Range col1 = worksheet.get_Range("A1", Missing.Value);
  xls.Range col2 = worksheet.get_Range("B1", Missing.Value);
  col1.EntireColumn.ColumnWidth = 70;
  col1.EntireColumn.WrapText = true;
  col2.EntireColumn.ColumnWidth = 25;
  
  // show dialog for results
  TaskDialog.Show("Success", "Exported " + numWarnings.ToString() + " warnings to Excel!!!");
 }
 catch (Exception ex)
 {
  TaskDialog.Show("Error", "Something bad happened!!!" + System.Environment.NewLine
      + System.Environment.NewLine + ex.Message);    
 }
 
}

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

Monday, May 02, 2016

RevitLookup 2017

I have compiled the latest source code for RevitLookup 2017 from Jeremy Tammik's GitHub (https://github.com/jeremytammik/RevitLookup).

Note: I did not create or edit this Revit Addin. I am only compiling it for those that don't understand or want to compile it for themselves.

Here is the download link: RevitLookup2017.zip

It is also listed on the right-hand column under downloads.

Wednesday, March 16, 2016

PDQ Deploy and Inventory for Autodesk and other applications

I have been using PDQ Deploy and Inventory for about 2 years now. It has been one of the highest ROIs on a product I have ever used. The ease, speed, and reliability of being able to push a product, product updates, and custom product settings out to 350+ PCs from a $1000 pair of tools has been a game changer for my company.


What is PDQ?

PDQ Deploy and PDQ Inventory (by Admin Arsenal) are a pair of applications that allow BIM Mangers, IT Admins, etc to deploy software and files silently across many PCs as well as keep an inventory of all the PCs software, hardware, and more. The programs do not require any pre-installation of software on the PCs and can install just about anything most companies need across a single office or multiple offices.













My Setup

My company currently uses PDQ to inventory well over 400 PCs and pushes deployments across 7 offices in 2 countries. We use PDQ inventory to track which PCs have which versions and service packs of all software applications, then use PDQ Deployment to automatically push updates to them. We also use PDQ to push out new versions of applications as they become available. Lastly, we use PDQ to deploy suites of applications to new systems within the company, gone are the old days of having a system image with everything installed.

PDQ Inventory

PDQ Inventory can tie into your Active Directory (AD) to quickly learn about all of the PCs within your company. My company has PCs in an AD container system like in the image below. By having PCs grouped based on office and whether it is a desktop/laptop/conference room/server, allows us to only inventory the PCs we want to use for deployments. We do not currently use PDQ Inventory or Deploy for servers.






















PDQ Inventory is used to create reports about which systems have which software as well as the version of the software. These reports are easy to build using the built-in report creator.



































PDQ Inventory also has what are called “collections”. The collections are live reports of PCs that meet the criteria of the collection. For instance in the next image, it shows all the PCs that have an Autodesk product installed, then the PCs that have Revit 2016 installed, and finally the PCs in each office that have Revit 2016 installed. These collections can be used as a source of PCs that PDQ Deployment can use to deploy a package to.




PDQ Deploy

PDQ Deploy allows you to create packages of applications, patches, and settings than you can then push remotely and silently to any number of PCs.

Creating a package in PDQ Deploy is as easy as specifying the msi, exe, bat, etc file that you want to deploy. By combing several steps (see image) you end up with a full blown package like the image below for Revit 2016, Dynamo, several addins, ini files and updates.




































Once you have a package built, you choose the PCs to push the package to. This can be from Active Directory, from a collection in PDQ Inventory, or even from a text file. We typically push out to about 10 PCs at a time. For PCs in other offices, we use a DFSR share to replicate all of the installation files to each office. Then the packages use a DFS namespace that is identical in each office to do the install from.

Here is the output for a package that installs AutoCAD Architecture 2016 (w/ SPs and hotfixes), uninstalls all pre-2015 Autodesk software on the PC, installs Revit 2016 (w/ addins, updates, ini files, etc), and Bluebeam PDF.




Conclusion


There are lots of other features that I won't touch on that include scheduling, automatic (start install when computer comes on), pre-made packages, and lots more.

The pair of applications have saved us countless hours for deploying software that the savings are probably immeasurable. If you want to try this out, the company has trial versions available. And if you have more questions about how we use it, please feel free to leave a comment.