Extract Part Atoms

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.