How to create SubD object by code using RhinoCommon?

I have found that the method Add(SubDEdge, Boolean) of SubDFaceList was defined as internal, not public, so how to create SubD object by code using Rhinocommon?

You can use SubD.CreateFromMesh like this:

import Rhino.Geometry as rg
from scriptcontext import doc
size = rg.Interval(-5,5)
box = rg.Box(rg.Plane.WorldXY, size, size, size)
mesh = rg.Mesh.CreateFromBox(box, 5, 5, 5)
subD =rg.SubD.CreateFromMesh(mesh)
doc.Objects.AddSubD(subD)
doc.Views.Redraw()

CreateSubD.py (261 Bytes)

1 Like

Thank you for your reply. However, I don’t konw how to crease one of the edges or vertexts by using such method.

You can use Mesh.UnweldEdge to add crease to any edge you want, then
use SubDCreationOptions.InteriorCreaseAtMeshEdge:

import Rhino.Geometry as rg
from scriptcontext import doc
import math
size = rg.Interval(-5,5)
box = rg.Box(rg.Plane.WorldXY, size, size, size)
mesh = rg.Mesh.CreateFromBox(box, 3, 3, 3)
mesh.Weld(math.pi)
mesh.UnweldEdge([27], True)
subDOptions = rg.SubDCreationOptions.InteriorCreaseAtMeshEdge
subD =rg.SubD.CreateFromMesh(mesh, subDOptions)
doc.Objects.AddSubD(subD)
doc.Views.Redraw()

CreateSubDWithCreases.py (399 Bytes)

Thank you very much! I will have a try.