How to Create a Navisworks Clash Test XML From Excel Using Python

Excel Clash Test Matrix to Clash Test XML Automation

Paul Kawuma
The Startup
4 min readSep 16, 2020

--

Photo by Negative Space from Pexels

Prior to picking up Python during lockdown in 2020, one of my pet peeves for the longest time was how time consuming preparing for the clash detection process can be and my inability to do something about it. I was unaware of the free tools available that could have improved the efficiency and flexibility of the process.

This post shows how to create an Autodesk Navisworks clash test XML file, starting with an excel clash detection matrix, with the use of Python. The time it took me to fill in hundreds of excel cells, on top of filling in hundreds of clash rule tests in Navisworks has been greatly reduced.

Navisworks XML

XML (Extensible Markup Language) is a markup language for representing structured information via a set of rules that encode a document into a format that can be read by both users and computers. An XML file can be supported by a schema file XSD (XML Schema Definition). The XSD defines and describes the elements of the XML allowing applications to verify and generate the XML. If you have Autodesk Navisworks Manage 2020 installed locally, the schema location for various versions can be found in “C:\Program Files\Autodesk\Navisworks Manage 2020\schemas”.

Python

This process requires the installation of Python (I recommend version 3.6.1 and above to avoid compatibility issues with the packages used in this article). My preferred code editor is Visual Studio Code (vscode) which supports working with Jupyter Notebooks (.ipynb) natively.

I recommend setting up a virtual environment for this process, albeit its not absolutely necessary. It is however, good practice since you avoid cluttering your global environment with different packages and versions from different projects, which can complicate testing of applications.

Pandas

Pandas is a data analysis python package that eases analysis of “relational” or “labeled” data. Pandas can be installed via pip from PyPI. You can type the command below into your terminal.

For more information on other installation methods, you can visit; https://pandas.pydata.org/pandas-docs/stable/getting_started/install.html

lxml

lxml is a python package for processing XML and HTML. lxml can also be installed via pip from PyPI. You can type the command below into your terminal.

For more information on other installation methods, you can visit; https://lxml.de/installation.html

Excel Clash Matrix

The excel clash detection matrix below is just a sample. The order of your matrix may differ from the one shown below. Therefore please note that the python code in this article will need to be edited to suit your requirements.

Note: As highlighted below; from cell F6, the remainder of the row to the right is left blank to avoid getting errors when creating the pandas dataframe. From my testing, this procedure helps to differentiate between the dataframe index and the header.

Excel Clash Matrix (clash tolerance values are only indicative)

The python code snippet below shows that the index_col and header attributes corresponds to the relevant excel rows and columns in the clash matrix above.

The output of the code above is shown below. The result is a Pandas DataFrame with a hierarchical indexing (MultiIndex) and a multi-level header.

Visualization snippet of the excel matrix as a Pandas DataFrame. (Only a few rows and columns are shown)

The dataframe generated from the sample clash detection matrix has the following information.

Putting It All Together

Although you can use a python script file (.py) to achieve the same result. If you are not too familiar with python, then I recommend that you use a Jupyter notebook (.ipynb) due to its flexibility and ease of combining code, computational output, text and visualizations into a single document.

Clash Tests

The following are the main items that are required when generating the clash tests portion of the XML.

  • Clash name
  • Clash type (Clearance “C” or Hard “H”)
  • Clash tolerance
  • Right locator
  • Left locator

Selection Sets

When generating the selection sets portion of the XML, for this scenario we primarily consider the following;

  • View folders (specific to discipline)
  • Selection set name
  • Conditions (the “contains” condition test is used to create search sets)

Entire Code

The full code is shown in the gist below.

Jupyter notebook

To conclude, this post shows how to save time when dealing with the repetitive processes of clash detection specifically, creating clash tests (and setting tolerances), creating selection sets (including organizing search sets into folders) inside Navisworks, etc…

Leave more time for the more important stuff! 🙂

--

--

Paul Kawuma
The Startup

Onwards and Upwards… Tech | Business | Automation