Revit 2014 OBJ Exporter and New SDK Samples

Funnily enough, after dealing with the new Revit 2014

custom exporter framework
last
week, and even suggesting rewriting my

Revit 2013 OBJ exporter
to make use of it, a request came in for a version of the

OBJ exporter for Revit 2014
, so I discuss that below.
I also add some more background to the list of new

Revit 2014 SDK samples
.
Finally, to wrap up, we’ll look at a surprisingly unbalanced distribution of Revit API

blog page views per country
.

OBJ Exporter for Revit 2014

As

mentioned
,
it would be nice to rewrite my OBJ exporter for Revit 2013 using the new Revit 2014 custom exporter framework.

However, a request already came in for a Revit 2014 version:

Question: Until now I have been using
Lumion for
visualisation.
It is fast and the result is OK.
However, I now discovered the
Octane renderer and
would like to try that as a visualisation tool instead.
Apparently, the only way to export a Revit model to Octane is via the OBJ file format.

Answer: In order to provide something immediately, I simply flat ported the Revit 2013 OBJ exporter to Revit 2014.
I also made use of the
DisableMismatchWarning utility
to fix the processor architecture mismatch warning MSB3270.

The current implementation thus still traverses all the Revit model elements one by one, retrieves their solids, exports the graphics face by face, and determines some, but not all, graphical attributes as described last year:

Some of that complexity could be removed by rewriting this using the Revit 2014 custom exporter API.
Above all, the graphical properties could easily be better supported.

Running the OBJ exporter on the RAC basic sample model generated these
OBJ and
MTL output
files and reported the following result:

OBJ exporter result in RAC basic sample model

Here is a sample visualisation in Octane of a Revit 2014 model exported to OBJ:

Octane rendering of Revit model exported to OBJ

As you can see, the texture mapping is rather strange.
Maybe the MTL file is not being properly processed.

Probably some face normals are also wrong, or, equivalently, the polygon loop vertex ordering is inverted.

Anyway, here is
ObjExport2014.zip containing
the complete flat ported source code, Visual Studio solution and add-in manifest for the Revit 2014 OBJ exporter.

Revit 2014 SDK Samples

I already presented the list of

new Revit SDK samples
without
going into much detail.

I fleshed it out a bit more for the

Revit API DevCamp in Moscow
,
as part of my presentation on the

Revit 2014 API
news.

The shortest useful summary of the main new API features that I have been able to achieve is this:

  • Copy and paste API – within or between documents, incl. view specific elements
  • Project browser API – commands, macros, selected elements
  • Schedule API – formatting, read-write data items
  • Command API – launch macro, add-in and built-in
  • Displaced elements API – exploded views
  • Join geometry API – create, remove and control joins
  • FreeForm element API – modification of imported solids
  • Site API – editing of topography surface points and sub-regions
  • Add-in API – loading and execution
  • Macro API – list, create, delete and execute
  • MEP calculations in external services
  • Structural Analysis SDK
  • Direct API access to rendering pipeline

The three last items are the only ones not covered by any new SDK samples.

For that reason, I recently went to some effort to explore the

Structural Analysis SDK
and the

custom exporter framework
.

The third item not covered yet concerns the MEP calculations in external services.
We are working on a good sample for that, hopefully coming soon.

All other important new features are covered by the following SDK samples:

  • DisplacementElementAnimation
  • DockableDialogs
  • DuplicateViews
  • ExtensibleStorageUtility
  • FreeFormElement
  • PostCommandWorkflow
  • ScheduleAutomaticFormatter
  • ScheduleToHTML
  • SinePlotter
  • Site
  • Units
  • WinderStairs

Several of these have already been discussed in the

DevDays online presentation, recording and sample code
and other separate posts.

Here is my Moscow DevCamp
Revit 2014 API slide deck that
includes one slide for each sample to provide a quick first impression of each.

Let’s close for today with something not directly API related:

BIM Boosting Booms Much More in Four Specific Countries

Cheers to Australia, Denmark, Netherlands and Sweden!

When I visited Harry Mattison in Boston in connection with the

Autodesk Tech Summit
, he mentioned that his
Boost your BIM page
views had an extremely unbalanced distribution for different countries, and very kindly provided some numbers correlated with the total country population:

Boost my BIM page views per capita

As you can see, the top four countries have 4, 5 and even up to almost 7 page views per 100000 population, whereas Canada has 2.5, the USA and UK well under 2, and the rest of the world well under 1.

Rather strange, isn’t it?

Thank you, Harry, for this perplexing little item.


Comments

22 responses to “Revit 2014 OBJ Exporter and New SDK Samples”

  1. Regarding exporting Revit scenes to Octane – there is now an integrated plugin available from Otoy to render Revit scenes in Octane from within Revit.

  2. Dear Paul,
    Thank you for the note.
    I guess you mean OctaneRender for Revit?
    http://render.otoy.com/manuals/Revit
    By you yourself, no less!
    Congratulations!
    Does it make use of the custom exporter framework?
    What did you think?
    Did you discover any interesting titbits worth sharing?
    Thank you!
    Cheers, Jeremy.

  3. Chris Melander Avatar
    Chris Melander

    Just as an FYI, the strange texture mapping that you see is due to the “rayepsilon” setting in the “Mesh Preview Kernel” being set too low. Essentially, its rendering multiple surfaces in the same plane. Raise the limit of the rayepsilon, and your problem should go away.
    http://render.otoy.com/manuals/ArchiCAD/?page_id=294

  4. Hi Jeremy
    Yes, the 2014 version of OctaneRender for Revit uses the custom exporter framework. The 2012 and 2013 versions use a much more complex geometry extraction system based on your originally posted code, but much more complex (in order to try to get assigned materials, generate UV’s, etc). The customer exporter framework is vastly simpler – a lot faster to load, and about 1/50th of the coding time :-)
    I’ve done some load time comparisons (ie. the time taking to get the geometry from Revit and load into Octane). Based on a 500k polygon scene the C# based Revit 2014 version is one of the fastest of the plugins I’ve written for the various architectural and design apps that I have written for Octane (which I was not expecting). I expected C++ non-managed to be significantly faster, but this was not the case.
    Not being able to obtain texturemap and bump map filenames for Revit materials is still an issue. The workaround employed by the plugin is to have a big XML file of Revit materials and the texturemaps and scales used for each of those materials. But this really needs to be made available by the Revit API.
    The biggest challenge was the limitations placed by the API when in a 3d perspective view. This was a constant challenge and there is a substantial amount of code to get around these limitations (given you will almost always be in a 3d perspective view when using the Octane plugin). The fact that the user cannot start the plugin whilst viewing a 3d perspective view is an annoyance, however not being able to start a transaction from a modeless dialog box whilst in 3d perspective mode required huge workarounds. Whilst this is thankfully all invisible to the user, the amount of code in the plugin dedicated to working around this limitation is substantial. For example, the user closes the plugin (modeless dialog) window, so the plugin needs to save the plugin data to the scene data, but this cannot be done because a transaction cannot be started. Or the user decides to save the current Octane rendertarget to the current Revit View, but of close the data cannot actually be saved at that exact point in time because the user initiated the command from the modeless dialog. Then the user switches to a new document – but the data from the old document has not been saved to the scene data yet. So the plugin has to save all it’s data to temporary memory when it is closed, and then needs to save to the scene data when the user triggers an event that can open a transaction. This is way more complex that it should be, and what took < 1hr to implement for other host apps took weeks to do in Revit. It is my belief that the API is there to assist plugin developers, so when limitations like this get imposed which cost plugin developers substantial amount of time, it is not ideal!
    Keep up the good work with your posts and code samples – they are invaluable to plugin developers.
    Paul

  5. Dear Paul,
    Thank you for your very interesting detailed description.
    I am very glad that the custom exporter works so well for you. Nice to hear.
    I am very sorry that the lack of API access in perspective views is causing such big problems for you. I can understand that. I created a wish list item for you: Issue REVIT-17844 [API wish: allow API use in perspective view].
    Cheers, Jeremy.

  6. Hi again Jeremy
    I am trying to migrate the plugin from loading from C:\ProgramData\Autodesk\Revit\Addins\2014 to the Store compatible .bundle format. I cannot get the plugin to load into Revit when the files are in “C:\ProgramData\Autodesk\ApplicationPlugins\OctaneRender for Revit.bundle”.
    In summary – when all the required .addin, .dat and .dll files are in C:\ProgramData\Autodesk\Revit\Addins\2014 the plugin is correctly addded to the Add-Ins toolbar. But copying all those files into the above .bundle folder results in the plugin not appearing on the toolbar. No error is raised. No amount of adding/editing xml files, putting the dlls in Contents, etc seems to be working. I have watched all the Autodesk videos on this and read all the doco. Can to advise how I can best resolve this issue pls?
    Thanks.

  7. Dear Paul,
    Nope, sorry, no idea off-hand how to resolve this.
    I’ll ask my colleagues for advice.
    Do you plan to submit your plugin as an exchange store app this week?
    If so, let’s make sure we get it fixed during the Portathon at the latest:
    http://thebuildingcoder.typepad.com/blog/2013/09/cloud-and-appstore-usage-grows-portathon-reminder.html
    Cheers, Jeremy.

  8. Dear Paul,
    Thank you again for your description and underlining how much effort the new framework can potentially save.
    I reused it the following new post:
    http://thebuildingcoder.typepad.com/blog/2013/09/access-to-individual-elements-in-linked-projects.html#5
    Cheers, Jeremy.

  9. Dear Paul,
    Have you downloaded and installed any other apps?
    To compare with?
    Cheers, Jeremy.

  10. Dear Paul,
    Does your add-in no longer load at all, or is it just a problem that it does not load dynamically during runtime, without restarting Revit?
    Cheers, Jeremy.

  11. Dear Paul,
    We have heard of the following issue regarding the new AllowLoadIntoExistingSession tag in the add-in manifest file:
    I created an add-in external application that just adds a ribbon panel to the add-in tab. It works fine if the bundle is placed in the C:\ProgramData\Autodesk\ApplicationPlugins folder before launching Revit. Then Revit displays my ribbon panel as expected.
    Now I would like to add the ribbon panel at runtime while Revit is running. I tried moving the bundle folder to C:\ProgramData\Autodesk\ApplicationPlugins after launching Revit, but Revit does not load it any longer.
    I set AllowLoadIntoExistingSession to true. If I don’t set it, it is still true by default.
    It works again if I skip the PackageContents and just put the add-in manifest file in the standard Revit specific location.
    Cheers, Jeremy.

  12. Dear Paul,
    Here is another thing to check:
    In my experience, you can use any encoding you want in the Revit add-in manifest, but it must correspond to the coding specified in the corresponding XML file tag, i.e., the tag must tell the truth:
    http://thebuildingcoder.typepad.com/blog/2010/12/snow-and-woe-with-manifest-files.html > Add-in Manifest File Encoding
    http://thebuildingcoder.typepad.com/blog/2010/04/addin-manifest-and-guidize.html#3
    Maybe that is the issue for you?
    Cheers, Jeremy.

  13. Thanks for all the suggestions Jeremy.
    The plugin does not load even after a Revit restart.
    It may be my Revit knowledge, but I found getting the plugin to run under the other Autodesk CAD packages to be relatively straightforward – and they also provide a reasonable level of diagnosis, whereas with Revit I was unable to determine if the plugin had in fact loaded or not. This is compounded by not being able to run Revit directly from the Visual Studio debugger (it crashes), so there is a need to run Revit from the desktop then attach in Visual Studio, by which time you may have missed some debug opportunities when the plugin loads.
    AllowLoadIntoExistingSession is not present in the addin file.
    My suspicion is that the plugin does not load from the C:\ProgramData\Autodesk\ApplicationPlugins folder because Revit is not loading the required dll’s when it’s in that folder, whereas they are loaded from C:\ProgramData\Autodesk\Revit\Addins\2014. But diagnosing this is very difficult. The other possibility is as you say, that it could be an XML issue.
    To add to my confusion, I downloaded your latest OBJ exporter, compiled it, copied (dll & addin) into C:\ProgramData\Autodesk\Revit\Addins\2014 and the ObjExport.dll did not load. I had to put ObjExport.dll into the Revit 2014 executable folder to get it to load.
    There needs to be a log file to indicate what is and is not being loaded, and if it’s not being loaded, why.
    Thanks again for your suggestions and comments. Very much appreciated.
    Paul

  14. Dear Paul,
    Sorry to hear about your struggles, and thank you for your appreciation.
    As you presumably know, we are running the Autodesk Exchange Store Portathon event today:
    http://thebuildingcoder.typepad.com/blog/2013/09/multireferenceannotation-example.html
    I therefore passed on your query to both the Revit API development team and my colleagues dealing with the exchange store, and they reply as follows:
    1. Do you have a PackageContents.xml file in the bundle folder?
    Revit is configured to look for Revit apps inside the PackageContents.xml files in this location.
    It is not configured to directly load .addin files from here.
    If the plugin is working from C:\ProgramData\Autodesk\Revit\Addins\2014, which seems to be the case, and you are ready to submit it to the appstore, we would generate a PackageContents.xml file for you and you can test it from there.
    2. We created an installer using the files submitted by the publisher. It seems to be working fine. The addin is getting loaded for Revit 2014. The bundle will be placed in ‘%ProgramData%\Autodesk\ApplicationPlugin’.
    We will be testing the app next week and contact the publisher regarding this directly.
    I hope this matches you intentions!
    Cheers, Jeremy.

  15. Thank you Jeremy. Yes that very much matches our intentions.
    Paul

  16. Dear Jeremy, how does this OBJ exporter for Revit 2014 work? I’m trying to create a workflow from Revit to Fusion 360 and it would be good to have an OBJ exporter without using 3DS Max or Rhino to do the job.
    I tried dling your zip file but its says that ObjExport.dll is missing.

  17. Dear Adriel,
    Great. Sounds like a good idea.
    I don’t know what you mean by ‘dling’, though.
    The OBJ exporter is a Revit add-in. It is installed exactly like all other Revit add-ins:
    http://thebuildingcoder.typepad.com/blog/about-the-author.html#2
    Oh, yes. My download does not include the compiled DLL .NET assembly, only the source code to compile and build it using Visual Studio.
    I do not provide the finished built product.
    Cheers, Jeremy.

  18. Hello Jeremy,
    I would like to use your plugin OBJ Export for revit to display the model in a web browser.
    But I want to integrate it to export for example the name of the objects but unfortunately do not know the C # language in which you have developed.
    You have a version in vb.net?
    I tried the fast converters online but unfortunately with poor results.
    Marco

  19. Dear Marco,
    Happy New Year to you!
    I am not a fan of VB :-)
    I have had excellent success using Reflector in the past, though:
    http://thebuildingcoder.typepad.com/blog/2013/05/external-command-lister-and-adding-ribbon-commands.html
    “I talked about Reflector way back in the early days of the blog. It since became commercial. Victor Chekalin mentioned using dotPeek, and my colleague Adam added that he uses the ILSpy .NET decompiler and is perfectly happy with that.”
    http://thebuildingcoder.typepad.com/blog/2008/10/converting-between-vb-and-c-and-net-decompilation.html
    http://www.jetbrains.com/decompiler
    http://ilspy.net
    Cheers, Jeremy.

  20. Dear Marco,
    By the way, are you sure that OBJ is the optimal way to display a Revit model in the web browser?
    You could also consider a more native web browser format, such as WebGL, e.g. via the Autodesk View and Data API:
    http://thebuildingcoder.typepad.com/blog/about-the-author.html#5.46
    Alternatively, for full control and total open source, you could take a look a the vA3C approach:
    http://thebuildingcoder.typepad.com/blog/2014/05/rvtva3c-revit-va3c-generic-aec-viewer-json-export.html
    If you do decide to use OBJ, please be aware that the add-in described above was implemented before the custom exporter functionality was introduced in the Revit 2014 API.
    As mentioned above, an improved OBJ exporter based on the custom exporter could probably be implemented now…
    Cheers, Jeremy.

  21. Hi, Jeremy
    I’ve learned a lot from your impressive work. I wonder if you have tried to export the model in Revit to Multipatch which is a 3D data type used in ArcGIS. I got a result by using arc toolbox in ArcGIS, but the coordinates are totally wrong. Now I really want to do this job by the code work, but I got no useful information from anywhere, so if you have some suggestion, that’ll be great.Thanks a lot.
    Lu

  22. Dear Lu,
    Thank you for your appreciation. It is the work of many!
    Nope, I have never heard of Multipatch.
    Maybe you need to use some global coordinate system to get any sensible results in ArcGIS.
    To convert from the Revit model coordinates to global ones related to North and East etc., please refer to the DirectionCalculation Revit SDK sample and the following discussions:
    http://thebuildingcoder.typepad.com/blog/2010/01/south-facing-walls.html
    http://thebuildingcoder.typepad.com/blog/2010/01/project-location.html
    Cheers, Jeremy.

Leave a Reply to Chris MelanderCancel reply

Discover more from Autodesk Developer Blog

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

Continue reading