Last week, we discussed how to use the Revit API to read the values of family parameters.
Another quick way to access all non-empty parameter values in a family file and see some other interesting family data as well is to simply make a call to the Application.ExtractPartAtomFromFamilyFile method.
It is mentioned in the What's New section of the Revit 2010 API help file. Its purpose is to export family data to XML for integration with Autodesk Seek. It opens an existing family file on disk and creates an XML file with data used by Autodesk Seek for content search. It takes two string arguments, the family file path and the path of an XML file to be generated. If there is a TXT type catalogue next to the family file (a TXT file with the same name as the RFA file), it will read that as well and process its contents into part atoms. The usage is simple:
if( doc.IsFamilyDocument ) { string path = doc.PathName; if( 0 < path.Length ) { app.ExtractPartAtomFromFamilyFile( path, path + ".xml" ); } }
I used the same simple column family generated by the Family API Lab 4 command which we used to examine the family parameter values, saved it to a file named 'column.rfa', and ran the code shown above to generate 'column.rfa.xml' with the following content:
<?xml version="1.0" encoding="UTF-8"?> <entry xmlns="http://www.w3.org/2005/Atom" xmlns:A="urn:schemas-autodesk-com:partatom"> <title>column</title> <id></id> <updated>2009-11-11T08:12:08Z</updated> <A:taxonomy> <term>adsk:revit</term> <label>Autodesk Revit</label> </A:taxonomy> <A:taxonomy> <term>adsk:revit:grouping</term> <label>Autodesk Revit Grouping</label> </A:taxonomy> <category> <term>23.25.30.11.14.11</term> <scheme>std:oc1</scheme> </category> <category> <term>Columns</term> <scheme>adsk:revit:grouping</scheme> </category> <link rel="design-2d" type="application/rfa" href="."> <A:design-file> <A:title>column.rfa</A:title> <A:product>Revit</A:product> <A:product-version>2010 or later one</A:product-version> <A:updated>2009-11-11T08:12:08Z</A:updated> </A:design-file> </link> <A:family type="user"> <A:variationCount>4</A:variationCount> <A:part type="user"> <title>600x900</title> <Tw units="mm">150</Tw> <Td units="mm">225</Td> <Depth units="mm">900</Depth> <Width units="mm">600</Width> </A:part> <A:part type="user"> <title>1000x300</title> <Tw units="mm">250</Tw> <Td units="mm">75</Td> <Depth units="mm">300</Depth> <Width units="mm">1000</Width> </A:part> <A:part type="user"> <title>600x600</title> <Tw units="mm">150</Tw> <Td units="mm">150</Td> <Depth units="mm">600</Depth> <Width units="mm">600</Width> </A:part> <A:part type="user"> <title>Glass</title> <Tw units="mm">150</Tw> <Td units="mm">150</Td> <Depth units="mm">600</Depth> <Width units="mm">600</Width> </A:part> </A:family> </entry>
You can see the same four types with the same parameter values listed. The unnamed type is skipped, as well as empty parameter values. I also note that the ColumnFinish material parameter does not appear here.
Jeremy,
Do you happen to have a class that we could deserialize this information back to? Say for example, if you wanted to read the xml files back into program.
I attempted to use VS2008 to create a scheme and auto create a class with xsd.exe but was unsuccessful.
Joel
Posted by: Joel Karr | November 22, 2009 at 14:30
Dear Joel,
No, I do not. The only experience I have with .NET and serialisation is described in
http://thebuildingcoder.typepad.com/blog/2009/07/store-structured-data.html
Cheers, Jeremy.
Posted by: Jeremy Tammik | November 23, 2009 at 07:20
I had actually made a family data reader very similiar to the seek one. Its good to see we ended up with some of the same decisions.
I believe the reason that ColumnFinish material parameter is not listed is because it returns an elementid and they did not want to search for the name that corresponed to the elementID. I too chose not to return any paramter that returned an elementID.
Serialization is actually really simple if you have a class to serialize. Maybe after AU I can write up a simple demo for you.
Posted by: Joel | November 23, 2009 at 10:38
Dear Joel,
Congratulations on that, it does indeed sound good. Yes, I as not surprisd to note the missing element id parameter, your explanation makes perfect sense to me. I agree that it is a simple schema, and a little demo is always more than welcome!
Cheers, Jeremy.
Posted by: Jeremy Tammik | November 24, 2009 at 08:16