Exporting 3dm file from grasshopper without baking

I’m new on the forum but I’m a long time reader.

I’m trying to write a python script in grasshopper to save a 3dm file arranging several breps in different properly organized layers.
It works fine, but I cannot set the model units properly: I need to save the file in meters instead of millimiters. I figured out I should use “ModelUnitSystem” but I cannot really figure out how.

Do you have any advice?

This is my code:

import Rhino

layer_indexes = {}
new_file = Rhino.FileIO.File3dm()
layers = new_file.AllLayers

for name, color in zip(layerNames, layersColorsRGB): 
    layer_indexes[name] = layers.AddLayer(name, color)

for brep, layer in zip(breps, target_layer):
    new_attributes = Rhino.DocObjects.ObjectAttributes()
    new_attributes.LayerIndex = layer_indexes[layer]
    new_file.Objects.AddBrep(brep, new_attributes)

if Trigger == True:
    print new_file.Write(file_path, 0)

This is the result:

After your

new_file = Rhino.FileIO.File3dm()

add a

new_file.Settings.ModelUnitSystem = Rhino.UnitSystem.Meters

I never used this method before, yet I found it easily thanks to auto-completion of c#:

… give it a try. I personally think it’s way easier to learn and explore rhinocommon with c#…

Thank you so much, it works perfectly!
I should really explore it, but sadly I have no background in C# so I should take a short course about it first. Meanwhile I’m tryng to survive with some basis of python, but sometimes I got really stuck.

My experience of python in grasshopper: it doesn’t speak, it doesn’t help you. Each object is gibberish and without type.
C#, instead, is “loud”. It always want you to give details of what you do.
Each object has a type and you can explore its sub-methods easily.

Sooner you try, sooner you’ll see how much simpler is to code in c# in grasshopper.

1 Like

I will try asap!

Here the final result in a demo for the record. =)

Exporter.gh (14.4 KB)

Most of the code is from: Exporting grasshopper geometry to rhino file without baking it - #3 by elevelle


Very cool, thanks! :+1: Two little things:

  1. I opened the file and clicked the trigger button, then couldn’t find the file. Discovered the internalized Path soon enough but it could be more explicit.

  2. The time-date in the filename is hard to read: Filename_240111145341.3dm
    More readable would be nice. Of course, I can edit the Python but… just saying.

P.S. You might want to add the following lines to the top of your Python, before import Rhino ?

ghenv.Component.Name = "Export 3dm File"
ghenv.Component.NickName = "X3dm"
__author__ = "Giulio Lucio Sergio Sacco @GiLuSSa"

And delete the outputs?


1 Like