How to Create a Navisworks Clash Test XML From Excel Using Python
Excel Clash Test Matrix to Clash Test XML Automation
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.
pip install pandas
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.
pip install lxml
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.
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.
cdm = pd.read_excel("name_of_your_excel_file.xlsx", sheet_name=0, index_col=[0,1,2,3,4], header=[0,1,2,3,4])cdm.head()
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.
The dataframe generated from the sample clash detection matrix has the following information.
Input:
cdm.info()Output:
<class 'pandas.core.frame.DataFrame'> MultiIndex: 127 entries, ('HW', 'A', 'HW0010', 'Pr_20_85_50', 'Masts and poles') to ('SL', 'C', 'SL6110', 'Pr_75_50_52', 'Sensors and detectors') Columns: 127 entries, ('HW', 'A', 'HW0010', 'Pr_20_85_50', 'Masts and poles') to ('SL', 'C', 'SL6110', 'Pr_75_50_52', 'Sensors and detectors') dtypes: float64(1), object(126)
memory usage: 65.5+ KB
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.
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! 🙂