Create solid from surface


I am working with C# in RhinoCommon. I want to create a solid-like cube from 6 surfaces. I already have the surfaces coded. Now, I want to create the solid and assign it to a layer to perform further operations. I know one of the ways could be:


But this creates a bool type of object which can’t be added to any layer.

What could be the solution to this?
I am flexible with the code i.e. I can use a different way to create this solid than the RunScript method or even a different way to assign it to layers(if that is possible).

Any suggestions are appreciated.

Well, if it was rhinoscriptsyntax, you would use LastCreatedObjects() to get the ID of the created solid.

The RhinoCommon method is here:

Thanks for the reply.
Actually before posting the question, I had a look on the link you shared. I could not make it work. Could you explain how this method works or maybe a very small template code(maybe 4-5 lines) might help.
When I used this, I was getting the error that it does not accept 7 arguments that I was giving, 6 surfaces and 1 tolerance.

in difference to commandline-Scripting, Rhinoscript, phyton-rhinoscript-Syntax Rhinocommon and the .3dm file distinguishes between geometry and attributes (layers, etc…)
so you create geometry, and you create attributes - finally you add an object with attributes to a document.

Background info:

your startingpoint:

It only wants two arguments - a list (array) of breps and the tolerance.

Hi, thanks for your reply.
I created a list and in theory, the solid. Now, when I add it to a layer, I get the error “Can’t convert Rhino.Geometry.Brep to Rhino.Geometry.Brep”
Here is my code:

   var brep = new Brep[6];
         brep[0] = surf[0].ToBrep();
         brep[1] = surf[1].ToBrep();
         brep[2] = surf[2].ToBrep();
         brep[3] = surf[3].ToBrep();
         brep[4] = surf[4].ToBrep();
         brep[5] = surf[5].ToBrep();

        var solid =  Brep.CreateSolid(brep, RhinoMath.UnsetValue);
            string layer_name = "solids";
            if (!string.IsNullOrEmpty(layer_name))
                int layer_index = doc.Layers.FindByFullPath(layer_name, true);
                if (-1 == layer_index)
                    layer_index = doc.Layers.Add(layer_name, System.Drawing.Color.Black);
                RhinoDoc.ActiveDoc.Layers.SetCurrentLayerIndex(layer_index, true);
                if (layer_index >= 0)
                    Rhino.DocObjects.ObjectAttributes attribs = doc.CreateDefaultAttributes();
                    attribs.LayerIndex = layer_index;
                    attribs.Name = layer_name;
                    doc.Objects.AddBrep(solid, attribs);

I know this is an issue with converting array to a single object. But I don’t understand why the object “solid” is an array despite using the createsolid command. Is there any way to retrieve single Brep object?
Sorry for bothering. And thanks in advance for the help

Because CreateSolid could create multiple closed Breps according to the input geometry…

And what could be a possible fix?

The fix is to see what’s in the output array, and if it’s a single valid Brep, simply reference it with the array index 0…

Here is some sample code in Python:

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

def CreateSolidTest():
    msg="Select intersecting surfaces to create solid"
    if not objIDs: return
    breps=[rs.coercebrep(objID) for objID in objIDs]
    if solid_result:
        for item in solid_result: new_ids.append(sc.doc.Objects.AddBrep(item))
    if new_ids: