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: 

export to dae file format

17 REPLIES 17
SOLVED
Reply
Message 1 of 18
c_hanschen
4463 Views, 17 Replies

export to dae file format

Is there a way to use the API to export a Revit 3D view to DAE format? (Collada)

 

I can use the Lumion exporter manually, bu can it be started from within the API?

 

A open source DAE project would be great, Like IFC. 

 

Thanks,

 

Chris

 

17 REPLIES 17
Message 2 of 18
jeremytammik
in reply to: c_hanschen

Dear Chris,

 

Thank you for your query.

 

You are talking about the digital asset exchange format?

 

https://en.wikipedia.org/wiki/COLLADA

 

https://www.khronos.org/collada/

 

I am not aware of any exporter for that format.

 

Theoretically, you can implement an exporter for any format you want yourself.

 

The custom exporter API was created for that very purpose, and people have used it to support a number of other file formats:

 

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

 

I hope this helps.

 

Best regards,

 

Jeremy



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

Message 3 of 18
c_hanschen
in reply to: jeremytammik

Sorry for the late response!

 

I am looking for a way to address the existing collada exporter with use of the Revit API.

not possible i think?

 

Always good to know the possibility of creating a custom exporter.

 

Thanks,

 

Chris

The Netherlands

Message 4 of 18
jeremytammik
in reply to: c_hanschen

You can launch custom commands using PostCommand:

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#5.3

 

http://thebuildingcoder.typepad.com/blog/2013/10/programmatic-custom-add-in-external-command-launch....

 

Therefore, presumably you can also drive the existing collada exporter programmatically, whatever that may be.

 

Cheers,

 

Jeremy



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

Message 5 of 18
Bernhard007
in reply to: jeremytammik

Hi Jeremy
Does the custom collada exporter work with Revit 2019 and 2020? Did not manage to get it work on 2019, the plugin is there but it does nothing when executed, and when debugging, on the command.cs file it tries the exporter.Export function, but always catches the ExternalApplicationException ex.
Im trying to work my way around learning the API programming, so am still learning.
Thank you

Message 6 of 18
jeremytammik
in reply to: Bernhard007

Dear Bernhard (Bond?),

 

Are you talking about the Custom Exporter to Collada for Revit 2014 published in July 2013?

 

https://thebuildingcoder.typepad.com/blog/2013/07/graphics-pipeline-custom-exporter.html#5

 

I would assume it should work pretty much unchanged.

 

Regarding the exception that it may throw, that issue has come up a couple of times in the past and is surprisingly easy to handle.

 

Simply add an exception handler to catch and handle the exception, and then ignore it.

 

In spite of throwing the exception, the custom exporter seems to work perfectly all right.

 

Here is a more detailed discussion and example of this:

 

https://thebuildingcoder.typepad.com/blog/2018/12/dynamo-symbol-vs-type-and-exporter-exception.html#...

 

https://github.com/jeremytammik/CustomExporterAdnMeshJson/commit/23a95aad8f4a3cca85a72b32e2b699bde1d...

 

Can you confirm that this solves the issue in your case as well?

 

Thank you!

 

Best regards,

 

Jeremy

 



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

Message 7 of 18
jeremytammik
in reply to: Bernhard007

Dear Bernhard,

 

An update:

 

I just noticed that I created a GitHub repository for the Collada custom exporter:

 

https://github.com/jeremytammik/CustomExporterCollada

 

Its list of releases includes one saying, 'added exception handler around call to exporter.Export':

 

https://github.com/jeremytammik/CustomExporterCollada/releases

 

Maybe you are already looking at that one, and not the one I mentioned in the initial answer?

 

Best regards,

 

Jeremy

 



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

Message 8 of 18
Bernhard007
in reply to: jeremytammik

Thank you for the quick response Jeremy, ah yes I always wanted to be a
secret agent, but it never worked out. So I resorted to architecture
instead (hence the 007). Maybe someday Ill design a top secret lab on top
of a mountain in Switzerland or something.

Anyhow, I actually used your latest github releases on
https://github.com/jeremytammik/CustomExporterCollada/releases , both the
one with the exception handler (2017.0.0.1) and the 2018.0.0.0 releases,
and both of them for some reason do not work neither on Revit 2018 nor 2019
(it does nothing after I click the custom addin on a 3D view). Might be
that there is something basic that I am missing?

When I run the debug, the log shows the following message: 'Object
reference not set to an instance of an object' (the image below - I added
the line 52 MessageBox.Show line for testing):
[image: VisualStudio_Debug error.png]

After this I commented out the exception handler and rebuilt the code, and
then received the following Revit error: "Revit could not complete the
external command. Contact the provider for assistance. Information they
provided to Revit about their identity: The Building Coder (image below).
[image: Revit_error.png]
(Visual studio image of commented code):
[image: VisualStudio_withoutException.png]

Just to ensure that I did not miss something obvious, here is the steps
that I took to recreate the scenario.

1: Downloaded the 2018 zip release file, unzipped and opened the .sln file
in Visual Studio 2017.
2. Reimported the RevitAPI.dll and RevitAPIUI.dll file from the Revit
folder, as they were not found when opening the .sln file initially
3. Changed the target framework to .NET Framework 4.7.1 (latest that I have
downloaded on this machine)
4. Built the project, added the CustomExporterCollada.dll as well as the
CustomExporterCollada.addin to the add-in folder of Revit 2019
5. Launched Debug for Revit 2019 in Visual studio, opened a demo project
and launched the addin from the external tools icon with a breakpoint on
the exporter.Export line of Command.cs in Visual Studio
6. Stepped through the code from here until the exception message is called.

I hope there is something basic that Im missing? Anyway, thank you for your
time thus far, I appreciate every bit of your work and help, makes it
really accessible for a newcomer to get started with developing plugins!

Thank you.
Message 9 of 18
Bernhard007
in reply to: Bernhard007

Update:
I see when debugging the project, on the MyExportContext file on the Start() method, when stepping through the code, the debugger goes to the "streamWriter = new StreamWriter("W:\\!Work\\Reit 2014\\test.dae");" line, and after that the (WriteXmlColladaBegin() and WriteXmlAsset(); methods are never called. The code then jumps to the Finish() method and only executes the WriteXmlLibraryGeometriesEnd() method before returning to the Command script and throwing the exception.
The file thus never goes through the process of writing any geometry data to the file. 
Would you perhaps know why this is?

Thank you

Message 10 of 18
jeremytammik
in reply to: Bernhard007

I do not see the images you refer to.

 



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

Message 11 of 18
Bernhard007
in reply to: jeremytammik

Sorry, the images did not attach with the post. Here they are now in the order that they appear in the previous post. But figured out in the meantime that the exception gets called in any case, and can be just ignored (by reading and understanding your previous posts better). It still does not export though.
What would be the expected outcome when following the steps to recreate the issue in my previous post (Something im perhaps missing)?

Message 12 of 18
Bernhard007
in reply to: jeremytammik

Update:
I see when debugging the project, on the MyExportContext file on the Start() method, when stepping through the code, the debugger goes to the "streamWriter = new StreamWriter("W:\\!Work\\Reit 2014\\test.dae");" line, and after that the (WriteXmlColladaBegin() and WriteXmlAsset(); methods are never called. The code then jumps to the Finish() method and only executes the WriteXmlLibraryGeometriesEnd() method before returning to the Command script and throwing the exception.
The file thus never goes through the process of writing any geometry data to the file. 
Would you perhaps know why this is?

public bool Start()
    {
      CurrentPolymeshIndex = 0;
      polymeshToMaterialId.Clear();

      streamWriter = new StreamWriter("W:\\!Work\\Reit 2014\\test.dae"); //default: W:\\!Work\\Reit 2014\\test.dae

      WriteXmlColladaBegin();
      WriteXmlAsset();

      WriteXmlLibraryGeometriesBegin();

      return true;
    }

    public void Finish()
    {
      WriteXmlLibraryGeometriesEnd();

      WriteXmlLibraryMaterials();
      WriteXmlLibraryEffects();
      WriteXmlLibraryVisualScenes();
      WriteXmlColladaEnd();

      streamWriter.Close();
    }


Thank you

Message 13 of 18
jeremytammik
in reply to: Bernhard007

Try creating the StreamWriter earlier on, already in the constructor, so that it is already set up and ready to go before beginning the actual export. Maybe there is some strange conflict between the .NET StreamWriter creation and the Revit API export context.

  

By the way, I updated the repository for Revit 2020. Can you update your code to match mine, so we are in sync? Thank you!

 



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

Message 14 of 18
jeremytammik
in reply to: Bernhard007

I moved the StreamWriter initialisation into the custom exporter constructor and tested successfully my end.

 

All work well now for me.

 

I captured this state in release 2020.0.0.2:

 

https://github.com/jeremytammik/CustomExporterCollada/releases/tag/2020.0.0.2

 

Can you confirm that it works for you too? Thank you!

 



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

Message 15 of 18
Bernhard007
in reply to: jeremytammik

Yes. Thank you Jeremy, the 2020.0.0.2 works perfect now. 
Thank you for your help, really appreciate it!

Message 16 of 18
jeremytammik
in reply to: Bernhard007

Thank you for the rather surprising and unexpected confirmation.

 

I wonder what you did wrong?

 

I did nothing to fix anything.

 

Oh yes, of course I did.

 

Well, hardly much, just what came to mind as you described your debugging observation and the weird jump from the stream writer initialisation to the end of processing.

 

What luck!

 

Cheers,

 

Jeremy

 



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

Message 17 of 18
jeremytammik
in reply to: Bernhard007
Message 18 of 18
zefreestijl
in reply to: jeremytammik

Hi Jeremy, thank you for sharing the code,

this add-in works great and is really helpful for converting the model into SketchUp.

 

Currently I tried to alter the script to fit the requirement in our company, (work environment is 2020)

there's still two issues I cannot solve, hopefully someone can give me any suggestions:

 

1. Somehow the diffuse color will be inverted while import into SketchUp,

so I tried to add a (256 - ) expression to get the correct RGB value in SKP;

but the method cannot solve the problem for transparency,

if there's any material has the transparency value for Shading,

the .dae file will not be imported into SKP.

zefreestijl_0-1630056260332.png

 

 

 

2. The objects will be in the same group when imported into SKP,

although I could filter the model by category and then export to multiple .dae files,

I was wondering if I could separate the geometries to each groups before export.

I've searched for a while and found this solution: 

zefreestijl_1-1630056275191.png

zefreestijl_2-1630056385285.png

 

 

the author separate two geometries with the library_nodes attribute,

I've tried to insert the code, but still don't know where can I start it.

 

zefreestijl_3-1630056401352.png

 

Sorry I couldn't upload the .dae file which contains grouped geometries, 

Here is the original source link:

https://forums.sketchup.com/t/importing-collada-dae-with-multiple-geometries-objects/129675

 

I hope someone can help me solve these problems.

since I just started learning Revit API, any hints will be a great help for me.

 

Thanks in advance. :]

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community