To tell the truth, today is not a vacation day, but the Swiss national holiday, right in the middle of my vacation.
In my last post, I mentioned various urgent and important issues that I still wanted to take care of.
I am very happy to tell you that these items all felt a lot less urgent and important after immersing myself in a couple of days of vacation in Avignon to visit family and attend some offerings of one of the world's biggest theatre events, the annual Avignon theatre festival, and especially its less official 'OFF' sibling, initiated by independent theatre companies.
The main reason for my visit were my relatives, though, and not the festival, although I did attend a couple of shows and loved the buzzing activity everywhere.
As I once mentioned, I also love the trip itself down to Avignon along back roads and desolate river gorges. The main discovery this time around was the beautiful Lac du Bourget, where I was mysteriously and magically lent a gorgeous wooden canoe to go paddling around in between rounds of swimming.
Meanwhile, here are a couple of work and Revit API related thingies that were either pending publication or hanging around my inbox that I would like to share with you:
- Revit API overview
- Presenting colour coded source code
- Preview control with linked document
- Calculating the mass of a building element
Revit API Overview
We regularly hear requests for a Revit API overview.
The first and foremost place to look is in the material provided in the Revit Developer Center and in the developer guide wiki. The Revit Developer Center provides a host of self-learning material as well.
The DevDays Online presentation on What's New in Revit 2013 and the follow-up Revit 2013 API webcast complementing it both discuss new features of the Revit 2013 API, and the first half of the latter is completely dedicated to the basics of the Revit API in general and is independent of the current version.
Ritchie Jackson also created a complete Revit API Introduction from a completely different point of view.
Presenting Colour Coded Source Code
Here are some tips on pasting colour coded source code into a PowerPoint slide deck.
a) Simple One-step Approach via HTML
- Use CopyToHTML in Visual Studio to copy the colour coded source code into the clipboard in HTML format.
- In PowerPoint, use Home > Paste > Arrow down > Paste Special... > HTML format to paste.
b) Safer Two-step Approach via Word and RTF
You may have a still better result using Word in an intermediate step. In that case, you don't even need to copy as HTML from VS; you can just use the standard copy. In Word, first paste the code, then select and copy it again from Word. Now, in PowerPoint, use Home > Paste > Arrow down > Paste Special... > RTF format to paste it in.
Colour Coded Source Code for Black Slides
If your slides use a black background, and you are using a white background in VS, your black source code will be invisible. In that case, in VS, you can go to Tools > Options... > Environment > Fonts and Colors > Item background and set that to black, set the item foreground to white, and hit OK.
Preview Control with Linked Document
I presented a minimal sample named PreviewControlSimple making use of it in my DevCamp session on the Revit 2013 UI API enhancements, and a more complete and complex one is given by the UIAPI Revit SDK sample.
Here is a question that was not yet addressed, though:
Question: Is it possible to use the preview control with a linked document? I tried to do so, and it throws an exception saying "Cannot preview a linked document".
Answer: This is by design: a linked document cannot be previewed using this control.
One workaround would be to close the project document, open the linked document and preview it then.
Calculating the Mass of a Building Element
And finally, another pretty fundamental little BIM question that has been hanging around waiting to be published for a while:
Question: How can I determine the mass of a building element?
I am working with data sets providing certain crucial calculation values based on material mass.
I can see how to calculate volume and area in the Revit API, but I see no API call to calculate mass.
Is there any way to calculate a Revit model element's material mass through the API?
Answer: You can query the material for its density, and ask the building element for its volume.
The volume obviously needs to be provided for several different materials per building element, e.g. for the different layers of the compound structure of a complex wall or floor, so you can use the Category.HasMaterialQuantities property to check which materials contribute volume and the Element.GetMaterialVolume method to determine the volume of a specific material for a given element.
The density can be obtained from the Density property on StructuralAsset, which can be retrieved from Material.StructuralAssetId and PropertySetElement.GetStructuralAsset.
That is all from me for now. I still have to relax a bit more...