How to subdivide a surface using Python script?

Ladybug component such as solar radiation analysis will subdivide the surface into smaller patches based on grid size specified.

May I ask how this is achieved using Python script, specifically the Rhinoscript commands used?


Dear buggers, advice is greatly appreciated! Thanks!

Hi Grasshope,

While I didn’t write that component myself. You need the RhinoCommon Mesh.CreateFromBrep method

search for it in the RhinoCommon -

Hi Grasshoppe,

Anton is right. You just need to set a number of meshing parameters based on the gridSize.

Here is the sample code that you can find in Honeybee_Generate Test Points:…


Thank you Anton and Mostapha!

I did a brute force “copy and paste” test of the following code, and it didn’t work with the warning of unable to determine the length of the brep objects.

I’m sure I get it wrong in this way, and I hope you can point out how to correct the errors.

import Rhino as rc
import Grasshopper.Kernel as gh
from itertools import chain
import System.Threading.Tasks as tasks
import rhinoscriptsyntax as rs

mesh = []

def createMesh(brep, gridSize):
** ## mesh breps**
** def makeMeshFromSrf(i, inputBrep):
mesh[i] = rc.Geometry.Mesh.CreateFromBrep(inputBrep, meshParam)[0]
print 'Error in converting Brep to Mesh…'

** # prepare bulk list for each surface**
** mesh = [None] * len(brep)

# set-up mesh parameters for each surface based on surface size**
** meshParam = rc.Geometry.MeshingParameters.Default**
** meshParam.MaximumEdgeLength = gridSize**
** meshParam.MinimumEdgeLength = gridSize**
** meshParam.GridAspectRatio = 1**

** for i in range(len(mesh)): makeMeshFromSrf(i, brep[i])

return mesh**

createMesh(brep, 0.1) (4.39 KB)


Make sure you have input parameter “brep” set to ‘List Access’ and Type Hint ‘Brep’ (see screen capture below). I’ve also added a “gridSize” input parameter so you can control the number of mesh faces.

Hope this helps.


File attached. (4.39 KB)

Thank very much, Stephen!

I found that unexploded Brep object will not be properly processed by the code: only the first surface within the Brep object will be converted to a mesh.

Can you kindly advise the rhinoscript to explode a Brep surface?

Thank you! (35.5 KB)

The easiest solution is to use the [Deconstruct Brep] component and plug in the output faces into Python. You would have to do this for the [Honeybee_Generate Test Points] component as well.

Concerning your second question below, that has to do with the way we call the function. In the Honeybee component, you will notice that Mostapha creates a new list from ‘createMesh’ and passes that through another function as an argument. So the organization is a bit different from what you’re doing.

Hope this helps.


Hi Grasshope

Is this what you are looking for? Check out the component Brep to Mesh



BreptoMesh AJZ (39.7 KB)