Read XML Files and Use In Revit with XML Support added to Bakery Package in DynamoBIM

XML files are everywhere. And in the BIM world, we have to deal with a range of different xml file schemas, such as BCF, Navisworks Clash Reports and Viewpoints, and so forth. Hiding inside these XMLs there is some very useful information. For example, BCF files often have Element IDs in the viewpoint.bcfv component, and Navisworks XML files often have point XYZ values. Can we easily get access to this information for use in Dynamo, and then in Revit?

Yes, we can! There were one or two ways to do this in Dynamo before, but here is my take on it…

Dynamo ships with IronPython, which in turn ships with an XML handler called ElementTree. I have created some basic nodes that give us access to ElementTree functions in Dynamo. Along the way, I learnt a bit about encoding and character sets. It turns out that Navisworks often inserts tricky characters into the XML (like the diameter symbol), so as a workaround (for now) I do a string encoding roundtrip to get rid of these problematic characters. In the same node, I create the ElementTree object: this is a special object that essentially represents structured information about the XML data. The initial import looks like this:

Once we have this ElementTree object in hand, we can start to do some interesting things, like:
Iterate through tree to get individual XML elements

iterate-4268193

and Show a hierarchical representation:

With the individual elements, we can Get Attribute names and values, and the Get the children of those elements:

Obviously, you can immediately do some nice lookups against these lists in Dynamo, depending what information you want. However, on large XMLs this can be quite slow. Happily, ElementTree provides some basic XPATH support, which looks a bit like this:

With the XPATH support and an understanding of the xml hierarchy, I have created a node to do XPATH calls straight to the ElementTree object:

Now that we can ‘snip’ out useful information from the XML, we can do interesting things with it, like make some points:

When it comes to BCF, its a little bit more challenging. I haven’t figured out how to unpack the bcfzip directly to memory (yet), so we have do that manual step first. Once we have a ‘folder’ from the BCFZIP, we can get the bcfv files from inside it and then get information from them, like this:

So, in the latest Bakery package are the nodes needed to read a variety of XML files, get information from them, and do some useful things with that information. It was a learning experience for me, and I hope its useful to you 🙂

version-9817403

5 1 vote
Article Rating
Subscribe
Notify of
guest

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Tito
Tito
1 year ago

Hi,   Thank you for sharing your experience. I’m new into dynamo programming and I’m wondering how realist is to use dynamo/phyton to create a revit model from a xml file??   At work I’ve been using a software called Liftdesigner to create a lift 3D model and 2D DWG file from an xlm configured on SAP and another platform called myleegoo. With expansion of BIM, a lot of client are requiring 2d drawings+ 3D model, therefore we’ve been shifting to Revit slowly, but once I export the 3D model created on Liftdesigner to revit I have to create section… Read more »