Thursday, January 15, 2009
Document.LoadFamilySymbol method in Revit API doesn't work for all symbols
I ran into this problem recently on an External Command I was working on. My command listed all of the available families in a directory, and allowed checkboxes to choose which one they would like to open. Further to this I listed the individual symbols from each family, so you could load just one of those instead of the whole family. My initial testing showed that this worked fine, however after getting some others to use it for a few weeks some errors cropped up on certain families. The error was that if you loaded an individual symbol, it wouldn't work, however loading the whole family did. The Revit API does not throw an exception if the loading of a family symbol was unsuccessful, so the way to check if the loading was successful is to use the 'out FamilySymbol' paramater of the LoadFamilySymbol method. Using that, and comparing working text files with not working text files showed that the ones that weren't working, had spaces after the symbol name, but before the comma, whereas the ones that were working didn't. When you use the inbuild Revit load family window, it must automatically check for this and trim all the white space, however the API call function doesn't - you must do that in your code. So when you use the LoadFamilySymbol method, make sure the string that represents your symbol has been .Trim()'ed first. Either that or make sure the person managing your families doesn't add extra spaces!
Posted by Rod at 11:02 AM