Create mesh object in Rhinoscript

Hi.

I am trying to create a mesh box in Rhinoscript, but I don’t know how to do it yet. Any suggestion?

Thanks in advance.

The rhinoscript help sample for AddMesh() illustrates adding a mesh box…

HTH, --Mitch

Edit: actually, sorry, the help example does not add a box. Following is Python - Rhinoscriptsyntax for adding a mesh box:

import rhinoscriptsyntax as rs

vertices = []
vertices.append((0.0,0.0,0.0))
vertices.append((5.0, 0.0, 0.0))
vertices.append((5.0, 5.0, 0.0))
vertices.append((0.0, 5.0, 0.0))
vertices.append((0.0, 0.0, 5.0))
vertices.append((5.0, 0.0, 5.0))
vertices.append((5.0, 5.0, 5.0))
vertices.append((0.0, 5.0, 5.0))

faceVertices = []
faceVertices.append((0,1,2,3))
faceVertices.append((0,1,5,4))
faceVertices.append((1,2,6,5))
faceVertices.append((2,3,7,6))
faceVertices.append((3,0,4,7))
faceVertices.append((4,5,6,7))

mesh=rs.AddMesh( vertices, faceVertices )
#if you want the edges to look sharp
rs.UnweldMesh(mesh, 10, True)

and here is the (vb) Rhinoscript version:

Option Explicit
Call TestAddMeshBox()
Sub TestAddMeshBox()
    
    Dim arrVertices(7)    
    arrVertices(0) = Array(0.0, 0.0, 0.0)
    arrVertices(1) = Array(5.0, 0.0, 0.0)
    arrVertices(2) = Array(5.0, 5.0, 0.0)
    arrVertices(3) = Array(0.0, 5.0, 0.0)
    arrVertices(4) = Array(0.0, 0.0, 5.0)
    arrVertices(5) = Array(5.0, 0.0, 5.0)
    arrVertices(6) = Array(5.0, 5.0, 5.0)
    arrVertices(7) = Array(0.0, 5.0, 5.0)

    Dim arrFaceVertices(5)
    arrFaceVertices(0) = Array(0, 1, 2, 3)
    arrFaceVertices(1) = Array(0, 1, 5, 4)
    arrFaceVertices(2) = Array(1, 2, 6, 5)
    arrFaceVertices(3) = Array(2, 3, 7, 6)
    arrFaceVertices(4) = Array(3, 0, 4, 7)
    arrFaceVertices(5) = Array(4, 5, 6, 7)

    Dim strMesh
    strMesh = Rhino.AddMesh(arrVertices, arrFaceVertices)
    'if you want the edges to look sharp '
    Call Rhino.UnweldMesh(strMesh, 10, True)

End Sub
1 Like

Thank you so much :slight_smile: