How to export a revit project to fbx format with all the materials and textures

Anonymous

How to export a revit project to fbx format with all the materials and textures

Anonymous
Not applicable

Hi everyone I'm trying to create a Revit plugin in which I have to export the document to FBX to be opened in Unity.

The export works fine, I'm able to open it in Unity but all the materials are gone.

 

Is there a way to export with materials ?

 

Here is my code to export to FBX

 

UIApplication uiApp = commandData.Application;
Document doc = uiApp.ActiveUIDocument.Document;

ViewSet viewSet = new ViewSet();
viewSet.Insert(doc.ActiveViewSet);

doc.Export("C:/......PATH......", "nameFBXExportedFile", viewSet, new FBXExportOptions());

Thanks by advance !

 

0 Likes
Reply
Accepted solutions (1)
25,362 Views
16 Replies
Replies (16)

jeremytammik
Autodesk
Autodesk

Dear Christophe,

 

Thank you for your query.

 

Before exploring the Revit API aspect of things, the first thing to do is to check whether the Revit user interface supports this functionality at all.

 

If not, it is almost certainly not available programmatically either.

 

For that, please discuss the issue and identify an optimal end user workflow with an application engineer, product usage expert, or product support.

 

Once you have got that part sorted out, it will be time to step into the programming environment.

 

I hope this clarifies.

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes

Anonymous
Not applicable
Accepted solution

Hi, so not sure if this is a solution for you, but try downloading the Twinmotion Revit FBX export plugin from www.twinmotion.com (it's free)

 

I love Twinmotion (based on game engine and all the work is done for you, rather than stetting up unity - plus it support VR) but the FBX export pluing gives you various options on how you want to break the model down and also on how you want the materials to be exported. (it also create a much smaller FBX file that the in-built Revit export to FBX function.

 

Worth trying

 

 

Anonymous
Not applicable

Thanks, It matches exactly my needs for this project 🙂

0 Likes

bimprovn.com
Explorer
Explorer

I try , you can download twinmotion add in and export FBX . Its great, i see full material . 

 

Link download add in : https://apps.autodesk.com/RVT/en/Detail/Index?id=5061930675590642657&appLang=en&os=Win64&autostart=t...

 

have fun 

 

0 Likes

corybarrJCA7L
Participant
Participant

The TwinMotion add-in is great, but I need to add some functionality that it doesn't have. Has anyone found a way to export to FBX with materials programmatically? TwinMotion did it, so it has to be possible. I was able to get it working with pyRevit, but the materials did not export. Any thoughts on where to go from here?

jeremy_tammik
Autodesk
Autodesk

I fiddled around a bit with exporting materials and textures implementing the OBJ exporter before the advent of the 3D custom exporter:

  

  

However, nowadays, the 3D custom exporter is probably easier and more effective to use. Afaik, several existing discussions here in the forum deal with how to handle materials, textures and UV mapping in custom exporters:

  

https://thebuildingcoder.typepad.com/blog/about-the-author.html#5.1

  

Maybe some of the discussions on handling materials for direct shapes well also help:

  

https://thebuildingcoder.typepad.com/blog/about-the-author.html#5.50

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open

corybarrJCA7L
Participant
Participant

Thanks Jeremy. The CustomExporter class does look very promising. That got me further down the road, but I did get stuck gain.

 

Specifically, I'm not sure how to create the export context. More precisely, I'd love to see a code example of a class that implements the IModelExportContext interface. There is this example here, but I'm not finding documentation on the export context itself. I managed to create a class the at least runs without throwing an exception, but it does leave me with the question "How do I specify the file's output path?" Another way to say this is "How do I translate this code to the CustomExporter framework?" doc.Export("E:\Exports", "testExport.fbx", viewSet, fbxExportOptions)

 

I see exporter.IncludeGeometricObjects, so this definitely seems to be on the right track. Any ideas where I can look for more documentation and examples?

 

Thanks a ton.

jeremy_tammik
Autodesk
Autodesk

Thank you for your appreciation. You can find a couple of IModelExportContext interface examples in the custom exporter samples presented by The Building Coder:

  

https://thebuildingcoder.typepad.com/blog/about-the-author.html#5.1

  

The first one listed there, by Arnošt Löbel, is very complete, demonstrating and exercising just about all possible aspects of the custom exporter functionality. Once you grok that, you will also see how simple it really is. Just implement all the interface members as stubs to begin with, and then see which ones you need to flesh out to achieve your goal.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open

corybarrJCA7L
Participant
Participant

Ah, I see. It's now on the developer to handle writing the output file with assistance from the helper methods. It's more work than I thought it would be, especially after seeing the FBXExportOptions class. That's fine. I'm pretty new to the Revit API, but not to related tools, so thanks for the insight.

 

Just so I understand the current API a bit better, is this statement true? In Unity and several other apps, you can export a scene/view/etc to an FBX in a couple lines:

 

corybarrJCA7L_0-1674845967304.png

 

That used to be the case in the Revit API:

corybarrJCA7L_1-1674845995497.png

But FBXExportOptions is obsolete, so people now use CustomExporter. The flip side is that this class doesn't understand the output specifics of particular file types, so the developer has to handle that themselves. Löbel's export approach is much more code than using filetype-specific exporters. In short, the Revit API moved away from filetype-specific exporters. The developers now need to understand the specs of the file type to export to. Is that a correct understanding? It's fine if so. It's just a lot more code that I would have thought.

 

I can see the flexibility in that file-agnostic approach. I can export exactly how I want without being limited to the configuration of the method params. But for this tool, I'd take the old FBXExportOptions or Unity-style approach to FBX-specific exporters if that's available in the current Revit API (with materials working). 

0 Likes

jeremy_tammik
Autodesk
Autodesk

Why do you claim that FBXExportOptions is obsolete. I don't know why. It is not marked so in the Revit 2023 API docs:

  

https://www.revitapidocs.com/2023/02b2efba-9d7c-88bc-b43e-a541e169d832.htm

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes

corybarrJCA7L
Participant
Participant

Perhaps "obsolete" is too strong of a word. But you mentioned "However, nowadays, the 3D custom exporter is probably easier and more effective to use."

 

At any rate, there doesn't seem to be a way to export to an FBX with materials using FBXExportOptions, so that approach won't work for me. However, Using the CustomExporter seems to require that I essentially write the raw FBX, which requires a deep understanding of the format. I've written raw OBJs, but FBX is much harder. I don't see how to get the VertIndices or the NormalsIndex for the geometry from the API, among other things.

 

At present, I'm not seeing a way to export an FBX with materials using the Revit API. This seems unlikely for a mature API, so I must be missing something. I'm just not sure what.

0 Likes

jeremy_tammik
Autodesk
Autodesk

Oh dear. Sorry, that is a complete misunderstanding. My complete (intended) statement should read:

  

Now that we have a 3D custom exporter at our disposal, it is easier and more effective to use that to implement OBJ export rather than traversing the entire database, reading the geometry from each element, and trying to interpret how it should be represented in a specific view.

  

If you are interested in the FBX export rather than OBJ, then OF COURSE you should use the full-fledged built-in functionality provided by the Revit end user product itself.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes

jeremy_tammik
Autodesk
Autodesk

Regarding FBX export with materials, have you searched elsewhere for a solution yet?

  

I see a lot of hits, e.g., looking for "revit export fbx with textures":

  

https://duckduckgo.com/?q=revit+export+fbx+with+textures

  

As always with the Revit programming, it is probably more effective to search for the optimal manual end user approach and best practices before even starting to think about an API approach.

   

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes

corybarrJCA7L
Participant
Participant

Yes. I export with materials and textures manually very often. It's so often that if I don't automate this, I'll be spending a lot of 2023 mindlessly clicking the same Revit buttons over and over.

 

I can't say that I'm further to my original goal, but I did confirm that manually exporting and exporting via the Revit API gives the same results: no materials or texture. (Apparently, there's a way to get the materials to re-appear if you open in 3DS Max, but that's extremely non-optimal for an automated pipeline.) The way I currently get materials is via a manual export from the TwinMotion plugin. I find it surprising that there's no way to do this in the API or even with Revit's UI. At any rate, the TwinMotion plugin offers a proof by existence that it's possible to make something like this. However, my searches on where to begin are coming up dry.

 

So now I've narrowed down my current question to the more focused question "How would I go about making a TwinMotion plugin of my own?" Or is it possible to automate calls to Revit plugins via the API? That way I could drop in TwinMotion or https://apps.autodesk.com/RVT/en/Detail/Index?id=5384686083898818572&appLang=en&os=Win64 then have that handle the exporting.

0 Likes

andrew8QEC8
Advocate
Advocate
This method no longer works as the Twinmotion exporter makes Datasmith files. However if you have Unreal Engine you should be able to export the datasmith file as FBX from Unreal Engine.
0 Likes

andrew8QEC8
Advocate
Advocate
The "full function" fbx exporter in Revit is not fully functional as it does not export the material shader components with the file. Is there some way around this with the API, without paying infinite money for 3D studio max? We want to use Blender, because the animation and render engine is just plain better. There are ways to export the material library but no way for it to be reassociated with each part that it was applied to. It simply doesn't work with manual user inputs.
0 Likes