Using the Built-In Revit AcGe Functionality

Anyone who ever used the AutoCAD API for geometrical purposes must be enamoured with AcGe.

On the other hand, the Revit geometry library is pretty meagre in comparison.

Wouldn't it be nice to be able to use all that powerful AcGe functionality in Revit as well?

Actually, if you take a look at the support DLLs included in the Revit main executable directory, AcGe is obviously present:

  C:\Program Files\Autodesk\Revit 2014 > dir *acge*

    Directory of C:\Program Files\Autodesk\Revit 2014

  02/05/2013  12:52 PM  1,679,688 acge19.dll
  02/05/2013  12:52 PM    501,064 acgex19.dll

    2 File(s)      2,180,752 bytes

Wow. Wouldn't it be nice to be able to access that?

Well, you can, actually.

Here is a small proof of concept created by Florian Schmid of SOFiSTiK AG demonstrating showing the usage of AcGe geometry classes in Revit.

He originally provided it for Revit 2013. I did not get around to testing and verifying it until now, on Revit 2014, so here are the archive files for both of these versions:

The latter contains the Visual Studio solution acge_revit.sln that includes three Visual Studio projects:

AcGeTest references the geometry_acge assembly, of course.

The AcGe headers and libs are those from the 2013 ObjectARX or ObjectARX 2014 installations, respectively. There is no need to modify them in any way.

The acge19.dll is automatically demand loaded when geometry_acge.dll is loaded. Because acge19.dll lives in the same location as revit.exe, it is found without problems, so no need to manually load it.

To get the example working, you have to adjust the 'Include Directory' and 'Additional Library Directories' of the geometry_acge project so that the ObjectARX headers and libraries can be found on your system.

Welcome back AcGe, how we’ve missed you!

Here are the steps I performed to install ObjectARX 2014 and migrate the sample to the new version:

The result is an error and warning free compilation (copy and paste somewhere or view source to see truncated lines in full):

------ Rebuild All started: Project: geometry_acge, Configuration: Debug x64 ------
  Stdafx.cpp
  AssemblyInfo.cpp
  curve_converter.cpp
  Generating Code...
  .NETFramework,Version=v4.0.AssemblyAttributes.cpp
  geometry_acge.vcxproj -> C:\a\vs\acge_revit\x64\Debug\geometry_acge.dll
------ Rebuild All started: Project: AcGeTest, Configuration: Debug Any CPU ------
  AcGeTest -> C:\a\vs\x64\AcGeTest.dll
========== Rebuild All: 2 succeeded, 0 failed, 0 skipped ==========

There was one more hiccup: the debug version had an erroneous C++ compilation setting, generating a Multi-threaded Debug DLL. I had to change that to generate a Multi-threaded DLL instead, to ensure that the correct runtime library is used.

Many thanks to Florian for pointing out and demonstrating the access to this powerful geometry functionality.

Disclaimer

Note that I am not sure of the legality of making use of this undocumented access.

If you plan to use this approach in a commercial product, I suggest checking with the appropriate Autodesk channels first.

I also took this opportunity of adding a license and a disclaimer to this blog itself, covering all its contents.

I recently discovered the importance of a license when starting to publish more diligently on GitHub.