Extract Part Atom Revisited

We briefly discussed the use of the

ExtractPartAtomFromFamilyFile
method in Revit 2010.
Now the question on using this method arose again in the context of the Revit 2011 API:

Question: I invoked the Autodesk.Revit.ApplicationServices.Application ExtractPartAtomFromFamilyFile method of on an RFA file, using the following code:


private void createPartAtomFile(
  Application app,
  string rfaFilePath,
  string partAtomFilePath )
{
  app.ExtractPartAtomFromFamilyFile(
    rfaFilePath,
    partAtomFilePath );
}

This threw an AccessViolationException with the following stack trace:


AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at extractPartAtomFromFamilyFile(AString* , AString* )
at Autodesk.Revit.ApplicationServices.Application.ExtractPartAtomFromFamilyFile(String familyFilePath, String xmlFilePath)
...
...

How can I avoid this exception and successfully generate the part atom XML for the RFA file?

Answer: Based on an answer to this question by my colleague Saikat Bhattacharya, I wrote a new Building Coder sample command CmdPartAtom to test run this method.
The command implementation is achieved in the following few lines of code and successfully generates the part atom XML file:


[Transaction( TransactionMode.Manual )]
[Regeneration( RegenerationOption.Manual )]
class CmdPartAtom : IExternalCommand
{
  public Result Execute(
    ExternalCommandData commandData,
    ref string message,
    ElementSet elements )
  {
    UIApplication uiapp = commandData.Application;
    UIDocument uidoc = uiapp.ActiveUIDocument;
    Application app = uiapp.Application;
    Document doc = uidoc.Document;
 
    Transaction trans = new Transaction( doc,
      "Extract Part Atom" );
 
    trans.Start();
 
    string familyFilePath
      = "C:/Documents and Settings/All Users"
      + "/Application Data/Autodesk/RAC 2011"
      + "/Metric Library/Doors/M_Double-Flush.rfa";
 
    string xmlPath = "C:/tmp/ExtractPartAtom.xml";
 
    app.ExtractPartAtomFromFamilyFile(
      familyFilePath, xmlPath );
 
    trans.Commit();
 
    return Result.Succeeded;
  }
}

Here is a screen snapshot of the resulting XML file displayed in the browser, with all except one of the A:part nodes collapsed:

ExtractPartAtom XML output

In Saikat’s words:
Looking at the exception you have received, I am not sure if it is related to the TransactionMode and RegenerationOption attributes used in your plug-in.
In my case, I used the Manual mode for both the attributes.
Please try using my code snippet and steps to see if it works well at your end too.

Many thanks to Saikat for this exploration!

Here is

version 2011.0.75.0 of
The Building Coder samples including the complete source code and Visual Studio solution with the new command.

More recently, we have heard that there is currently a problem with this API call on 64 bit systems, so right now this will only work in the 32 bit version.
As Steve points out below, the issue might be occurring only on certain platforms, e.g. on 64 bit Windows 7 OS running 64-bit Revit Architecture 2011.
It has been resolved internally, though, so the next update should have the issue fixed.


Comments

6 responses to “Extract Part Atom Revisited”

  1. Steve Germano Avatar
    Steve Germano

    I have successfully used the atom extractor in XP 64 bit, I wonder if others are having problems in Win 7?

  2. Dear Steve,
    Oh, yes, the report that I saw was indeed working on Windows 7. Thank you for pointing that out! I added a note on that above as well.
    Cheers, Jeremy.

  3. A update to this, in 2011 on windows 7 only we have still had it fail on certain families that have formulas in them, once formulas are deleted the atom extractor runs correctly. I will be submitting to the dev team tomorrow for further investigation.

  4. Mona Akkoush Avatar
    Mona Akkoush

    Hi Jeremy,
    Kindly, I am getting a System.AccessViolationException when I try to execute this code:
    newFamInstElem = activedoc.Create.NewFamilyInstance(f, p, basisXYZ, elemFamSymb)
    -f is a Face of a wall element found in a linked revit file to the activedoc. f is not null
    -p is an XYZ point location on the face
    -basisXYZ is the X-axis
    -elemFamSymb is the new family instance symbol
    Please advise if this exception is due to the fact that am trying to access the face of a wall in a linked document & if there’s a solution to this issue.
    Thanks a lot..
    Best Regards,

  5. Dear Mona,
    I am going on vacation in the next few days. If you prefer having an answer before I return ten days later, and if you want a guarantee for an answer at all, and someone who can take some time to investigate yuor issue in any depth, I would advise you to submit an ADN DevHelp Online request for it.
    Otherwise, we’ll see what I can do for you in November … although I’ll probably be up to both ears in Autodesk University preparations by then :-)
    Cheers, Jeremy.

  6. Mona Akkoush Avatar
    Mona Akkoush

    Have a nice vacation Jeremy :-)
    Thanks a lot for your instant replies
    Best regards,

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading