Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

16 REPLIES 16
SOLVED
Reply
Message 1 of 17
Anonymous
23213 Views, 16 Replies

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

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 !

 

16 REPLIES 16
Message 2 of 17
jeremytammik
in reply to: Anonymous

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

Message 3 of 17
Anonymous
in reply to: jeremytammik

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

 

 

Message 4 of 17
Anonymous
in reply to: Anonymous

Thanks, It matches exactly my needs for this project 🙂

Message 5 of 17
bimprovn.com
in reply to: Anonymous

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 

 

Message 6 of 17
corybarrJCA7L
in reply to: Anonymous

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?

Message 7 of 17

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
Message 8 of 17

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.

Message 9 of 17

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
Message 10 of 17
corybarrJCA7L
in reply to: Anonymous

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). 

Message 11 of 17

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
Message 12 of 17
corybarrJCA7L
in reply to: Anonymous

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.

Message 13 of 17

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
Message 14 of 17

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
Message 15 of 17

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.

Message 16 of 17
andrew8QEC8
in reply to: Anonymous

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.
Message 17 of 17
andrew8QEC8
in reply to: jeremy_tammik

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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Customer Advisory Groups


Rail Community