Batch export

Hi everyone,

I have been trying to figure out a way to export all my individual layers in rhino file to individual fbx files.

https://wiki.mcneel.com/developer/scriptsamples/exportlayerobjects

here is the script I have tried, which unfortunately gives me “error writing file” at the exportation stage (loading and running it is ok).

fbx.rvb (1.2 KB)

Is there any method of importing layers into individual fbx files?

Hi Dennis,

the example posted in the link above exports in 3dm format which does not ask the user for export settings as the fbx exporter requires. So changing the export extension to fbx in the script is not enough. If you manually export some objects as fbx, you’ll see that first a settings dialog comes up followed by the mesh settings dialog (in case meshable objects are selected on the layer to export).

These two dialogs are surpassed when running the Export command with the dash in front (_-Export), so the dialog values are queried from the commandline. If you just want to accept the default values, you’ll need to add _EnterEnd in your Rhino.Command call like this:

Rhino.Command "_-Export " & strFile & " _EnterEnd", 0

Note that fbx format does not support all object types which are supported by 3dm format. If one of your layers contains eg. only curves, the export will not work. It might be best if you either lock such objects before exporting the layers out of Rhino or let the script just select objects which are supported by the fbx exporter.

_

c.

1 Like

Hi clement,

Thank you for your detailed explanation.

I thought I understood your comment and added the command line you suggested to the script I referred to,

However it is still giving me error at the saving stage.

My layers only contain 3d objects such as simple extruded cubes and rectangular objects.

Below is the copy of what my Rhino goes thru to obtain the error.

Again, thank you in advance.

Export FBX Options ( ExportNurbsObjectsAs=Mesh ExportMaterialsAs=Phong ExportFileAs=Version7Binary ):
Choose meshing option ( DetailedOptions PolygonDensity=50 ):

Created a mesh with 24 points and 8 polygons.
Meshing… Press Esc to cancel
Error writing file C:\Users\a\Desktop\test2_RoofWindow::Window.fbx
Error saving file C:\Users\a\Desktop\test2_RoofWindow::Window.fbx
No objects added to selection.
384 extrusions, 480 polysurfaces added to selection.

Hi Dennis,

i see now the script does not like to export sublayers. Since it creates the export file from the full layer path, a sublayer gets these :: in the path which is not allowed. Below is a changed script, you might compare the results with the variable blnFullPath set to True or False. If it is set to True, a layer named “Window” which is a sublayer of another layer “RoofWindow” gets exported to this location and path:

C:\Users\a\Desktop\test2_RoofWindow_Window.fbx

If blnFullPath is False, it will not include the parent layer name(s) in the path and export the Window layer without the parent Layer name in the file name like this:

C:\Users\a\Desktop\test2_Window.fbx

I would leave it using “True” to avoid overwriting exported fbx files in case you have multiple layers (or sublayers) with the same name.

BatchExportLayersToFbx.rvb (1.7 KB)

_
c.

1 Like

This script is great! I had one question as I tried updating it myself but never got it to run properly. I was looking to see if it was possible to modify the script so that before exporting the layers, it would set the origin for each layer to be at the lower corner of an invisible bounding box surrounding the items on the layer. Is this possible?

For context, I got these 3d scenes from Evermotion under the assumption that they were individual modeled assets. Now that I have spent so much money on the files I am kinda stuck trying to figure this out. My reasoning for this is that I am importing 3ds max scenes into Rhino as FBX and then exporting each element of the scene as an individual FBX file. Then uploading these into Lumion as custom assets. Setting the origin point to the bottom corner of each layer helps me later adjust position and orientation in Lumion much easier.

Any suggestions on how to get the script to run would be great! Or if you have any suggestions for a different/more efficient workflow it would be greatly appreciated! Thank you in advance :slight_smile:

Hi @Noah_Bennett,

it’s been a while since i scripted using old RhinoScript (rvb) so i’ve tried to do it in Python instead.

Below script uses the _ExportWithOrigin command and takes the lower left bounding box point of all objects on each layer as origin. Layers which are hidden or locked are ignored. It should work for all shadeable objects as long as they are selectable. The script now prompts for the folder to export to instead of using the saved document’s path…

To try it (with Rhino 7) use _RunPythonScript or to look inside use _EditPythonScript

BatchExportLayersToFbxWithOrigin.py (3.2 KB)

_
c.

Thank you so much, the script worked perfectly! You just saved me so much time and headache, I really appreciate it!