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
Solved! Go to Solution.
Solved by jeremytammik. Go to Solution.
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
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
You can launch custom commands using PostCommand:
http://thebuildingcoder.typepad.com/blog/about-the-author.html#5.3
Therefore, presumably you can also drive the existing collada exporter programmatically, whatever that may be.
Cheers,
Jeremy
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
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:
Can you confirm that this solves the issue in your case as well?
Thank you!
Best regards,
Jeremy
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
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
I do not see the images you refer to.
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)?
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
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!
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!
Yes. Thank you Jeremy, the 2020.0.0.2 works perfect now.
Thank you for your help, really appreciate it!
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
Preserved for posterity here:
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.
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:
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.
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. :]