Meshing rhino3dm.Extrusion created in python only

I am currently working on a project where i use a Rhino PolylineCurve to make an Extrusion, to be able to generate objects with the same profile but different lengths. These objects i want to then use in honeybee to make an Irradiance Analysis.

There is also a module from honeybee to directly convert an Extrusion to a Honeybee Model, but i have the Problem that the Extrusion.GetMesh() function returns None.

As i understand it correctly this is because the Extrusion Object was not loaded in Rhino and set the Display Mode to Shaded. Is there a way to set the Display Mode in python or to get the object meshed otherwise? I saw some examples where a Mesh was created manually and then added to the object (Link), but i have a rather complex geometry (looks like an extruded metal profile).

When i added the Extrusion to the model and saved it as 3dm file, i can open it in Rhino and set the Display Mode to shaded and i can use it in Honeybee. But i want to avoid that, as i want to generate the models for the Irradiance Analysis automatically.

My Code to generate the Extrusion and add it to the model.

import rhino3dm as rhino

model = rhino.File3dm.Read('test.3dm')

for object in model.Objects:
    if isinstance(object.Geometry, rhino.Curve):
        polyCurve = object.Geometry
        extrusion = rhino.Extrusion.Create(polyCurve, 10.0, True)

model.Objects.AddExtrusion(extrusion)
model.Write('extrusion.3dm', 8)

Any help appreciated.

Greetings,
Yannick

The module rhino3dm does not contain meshing functionality. It can only provide meshes that are saved in the 3dm file. Typically this means saving a 3dm with a viewport in Shaded or Rendered mode in Rhino.

So your only option is to do exactly that. (Or write your own mesher).

And before you ask: no, most of the geometry kernel functionality on can find in Rhino is not part of rhino3dm either.

It is pretty much only a fileformat access library for reading and writing 3dm files, with only the most basic geometry functions.

Thank you for the quick reply, than i will have a look how i handle it :slight_smile:

One thing to add is that rhino3dm does allow you to set a mesh on the extrusion, but you have to generate the mesh yourself. See this example:

import rhino3dm
model = rhino3dm.File3dm.Read('../models/MeshBox_r5.3dm')

mesh = model.Objects[0].Geometry

bbox = rhino3dm.BoundingBox(-10,-10,0, 10,10,20)
box = rhino3dm.Box(bbox)

extrusion = rhino3dm.Extrusion.CreateBoxExtrusion(box, False) #this extrusion is fine
extrusion.SetMesh(mesh, rhino3dm.MeshType.Render) 

outModel = rhino3dm.File3dm()
outModel.Objects.AddExtrusion(extrusion, None)
outModel.Write('../models/ExtrusionBox_r8.3dm')

Here I get an existing mesh from a Rhino model and set it as the render mesh for the extrusion. The extrusion is a very simple box.

The key line:

extrusion.SetMesh(mesh, rhino3dm.MeshType.Render) 

I could see one developing this further for simple primitives like spheres and cylinders, but beyond that it will get tricky.