SubDMesh (Subdivision Mesh) represents a modern mesh object capable of smoothing, creasing, and complex organic modeling. Unlike legacy PolygonMesh, it supports n-gon faces, varying smoothness levels, and edge/vertex weighting.
Autodesk.AutoCAD.DatabaseServices
System.Object
└─ RXObject
└─ DBObject
└─ Entity
├─ SubDMesh
| Property | Type | Description |
|---|---|---|
SubdivisionLevel |
int |
Current smoothness level (0=unsmoothed). |
VertexCount |
int |
Number of vertices. |
FaceCount |
int |
Number of faces. |
Volume |
double |
Volume (if watertight). |
SurfaceArea |
double |
Surface area. |
| Method | Return Type | Description |
|---|---|---|
SetSubdivisionLevel(int) |
void |
Sets smoothness. |
SetBox(...) |
void |
Creates a mesh box. |
SetSphere(...) |
void |
Creates a mesh sphere. |
SubdivideFace(int) |
void |
Refines a specific face. |
ExtrudeFaces(...) |
void |
Extrudes faces. |
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTableRecord btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
SubDMesh mesh = new SubDMesh();
// 10x10x10 box with 4x4x4 subdivisions
mesh.SetBox(10, 10, 10, 4, 4, 4);
btr.AppendEntity(mesh);
tr.AddNewlyCreatedDBObject(mesh, true);
tr.Commit();
}mesh.SetSubdivisionLevel(2); // Smooths the mesh geometryPoint3dCollection vertices = new Point3dCollection();
vertices.Add(new Point3d(0,0,0));
vertices.Add(new Point3d(10,0,0));
vertices.Add(new Point3d(0,10,0));
// ...
Int32Collection faceCounts = new Int32Collection();
faceCounts.Add(3); // Triangle
Int32Collection faceIndices = new Int32Collection();
faceIndices.Add(0); faceIndices.Add(1); faceIndices.Add(2); // Vertex indices
SubDMesh mesh = new SubDMesh();
mesh.SetSubDMesh(vertices, faceIndices, faceCounts.Count);// SubDMesh can be converted to Solid3d if it encloses a volume
if (mesh.Watertight)
{
Solid3d sol = mesh.ConvertToSolid(false, false);
// Add sol to database...
}// Convert to Surface (NURBS)
Autodesk.AutoCAD.DatabaseServices.Surface surf = mesh.ConvertToSurface(false, false);// Access vertices directly
// Warning: This can be large
foreach (Point3d pt in mesh.Vertices)
{
// ...
}// Apply crease to maintain sharp edges during smoothing
FullSubentityPath[] edges = ...; // Need to identify edges
mesh.SetCrease(edges, 1.0); // Full crease// Advanced: Extruding a subentity face
FullSubentityPath facePath = ...;
mesh.ExtrudeFaces(new[] { facePath }, 5.0, 0.0);- Watertight Check: Check
Watertightproperty before attempting volume calculations or solid conversion. - Level of Detail: High
SubdivisionLevelexponentially increases vertex count. Keep it low for performance. - Subentities: Manipulating individual faces/edges requires identifying them via
GetSubentPathsAtGsMarkeror similar selection mechanisms.
- Solid3d
- PolygonMesh (Legacy)