Create Meshes

A rectangular mesh (PolygonMesh object) represents the surface of an object using planar facets. The density or number of facets for a mesh is defined in terms of a matrix of M and N vertices, similar to a grid consisting of columns and rows. M and N specify the column and row position, respectively, of any given vertex. You can create meshes in both 2D and 3D, but they are used primarily for 3D.

Create an instance of a PolygonMesh object and then specify the density and placement of the vertices for the new mesh. This method optionally takes six values: the type of Polygon Mesh to create, two integers that define the number of vertices in the M and N directions, a collection of points containing the coordinates for all the vertices in the mesh, and two booleans that define if the mesh is closed in the M or N directions.Is

Once the PolygonMesh is created, use the IsMClosed and NClosed properties to close the mesh.

Create a polygon mesh

This example creates a 4×4 polygon mesh. The direction of the active viewport is then adjusted so that the three-dimensional nature of the mesh is more easily viewed.

VB.NET

<CommandMethod("Create3DMesh")> _
Public Sub Create3DMesh()
'' Get the current document and database, and start a transaction
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database

Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
'' Open the Block table for read
Dim acBlkTbl As BlockTable
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, _

'' Open the Block table record Model space for write
Dim acBlkTblRec As BlockTableRecord
acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _
OpenMode.ForWrite)

'' Create a polygon mesh
Dim acPolyMesh As PolygonMesh = New PolygonMesh()
acPolyMesh.SetDatabaseDefaults()
acPolyMesh.MSize = 4
acPolyMesh.NSize = 4

'' Add the new object to the block table record and the transaction
acBlkTblRec.AppendEntity(acPolyMesh)

'' Before adding vertexes, the polyline must be in the drawing
Dim acPts3dPMesh As Point3dCollection = New Point3dCollection()

For Each acPt3d As Point3d In acPts3dPMesh
Dim acPMeshVer As PolygonMeshVertex = New PolygonMeshVertex(acPt3d)
acPolyMesh.AppendVertex(acPMeshVer)
Next

'' Open the active viewport
Dim acVportTblRec As ViewportTableRecord
acVportTblRec = acTrans.GetObject(acDoc.Editor.ActiveViewportId, _
OpenMode.ForWrite)

'' Rotate the view direction of the current viewport
acVportTblRec.ViewDirection = New Vector3d(-1, -1, 1)
acDoc.Editor.UpdateTiledViewportsFromDatabase()

'' Save the new objects to the database
acTrans.Commit()
End Using
End Sub

C#

[CommandMethod("Create3DMesh")]
public static void Create3DMesh()
{
// Get the current document and database, and start a transaction
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;

using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
// Open the Block table record for read
BlockTable acBlkTbl;
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,

// Open the Block table record Model space for write
BlockTableRecord acBlkTblRec;
acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
OpenMode.ForWrite) as BlockTableRecord;

// Create a polygon mesh
PolygonMesh acPolyMesh = new PolygonMesh();
acPolyMesh.SetDatabaseDefaults();
acPolyMesh.MSize = 4;
acPolyMesh.NSize = 4;

// Add the new object to the block table record and the transaction
acBlkTblRec.AppendEntity(acPolyMesh);

// Before adding vertexes, the polyline must be in the drawing
Point3dCollection acPts3dPMesh = new Point3dCollection();

foreach (Point3d acPt3d in acPts3dPMesh)
{
PolygonMeshVertex acPMeshVer = new PolygonMeshVertex(acPt3d);
acPolyMesh.AppendVertex(acPMeshVer);
}

// Open the active viewport
ViewportTableRecord acVportTblRec;
acVportTblRec = acTrans.GetObject(acDoc.Editor.ActiveViewportId,
OpenMode.ForWrite) as ViewportTableRecord;

// Rotate the view direction of the current viewport
acVportTblRec.ViewDirection = new Vector3d(-1, -1, 1);
acDoc.Editor.UpdateTiledViewportsFromDatabase();

// Save the new objects to the database
acTrans.Commit();
}
}
VBA/ActiveX Code Reference