我一直在研究 AutoCAD API 的 PolygonMesh 类。我想用网格画一个简单的盒子。这是我编写的一个简单方法,用于查看 PolygonMesh 的行为
[CommandMethod("TESTSIMPLEMESH")]
public void TestSimpleMesh()
{
// Get the current document and database, and start a transaction
Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
BlockTable acBlkTbl = acTrans.GetObject(_database.BlockTableId, OpenMode.ForRead) as BlockTable; // Open the Block table record for read
BlockTableRecord acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; // Open the Block table record Model space for write
// Create a polygon mesh
PolygonMesh acPolyMesh = new PolygonMesh();
acPolyMesh.MSize = 4;
acPolyMesh.NSize = 4;
acPolyMesh.MakeNClosed(); //What is N???
acPolyMesh.MakeMClosed(); //What is M???
// Add the new object to the block table record and the transaction
acBlkTblRec.AppendEntity(acPolyMesh);
acTrans.AddNewlyCreatedDBObject(acPolyMesh, true);
//Creating collection of points to add to the mesh
Point3dCollection acPts3dPMesh = new Point3dCollection();
acPts3dPMesh.Add(new Point3d(100, 100, 0));
acPts3dPMesh.Add(new Point3d(200, 100, 0));
acPts3dPMesh.Add(new Point3d(200, 200, 0));
acPts3dPMesh.Add(new Point3d(100, 200, 0));
acPts3dPMesh.Add(new Point3d(100, 100, 100));
acPts3dPMesh.Add(new Point3d(200, 100, 100));
acPts3dPMesh.Add(new Point3d(200, 200, 100));
acPts3dPMesh.Add(new Point3d(100, 200, 100));
//Converting those points to PolygonMeshVertecies and appending them to the PolygonMesh
foreach (Point3d acPt3d in acPts3dPMesh)
{
PolygonMeshVertex acPMeshVer = new PolygonMeshVertex(acPt3d);
acPolyMesh.AppendVertex(acPMeshVer);
acTrans.AddNewlyCreatedDBObject(acPMeshVer, true);
}
// Save the new objects to the database
acTrans.Commit();
}
}
我希望该方法做的是绘制一个简单的 block 。相反,我得到了一个 block ,但有些行回到原点:
如何更改此方法,使其只绘制方框?
此外,如果有人可以解释与网格相关的 M 和 N 值,那就太棒了。
最佳答案
来自 AutoCAD ObjectARX 帮助文件:
PolygonMesh.MSize
Accesses the vertex count in the M direction. This is the number of vertices that will be used to make up an M row in the PolygonMesh if the PolyMeshType is SimpleMesh. For any other PolyMeshType, the M surface density value will be used as the row size.
PolygonMesh.NSize
Accesses the vertex count in the N direction. This is the number of vertices that will be used to make up an N column in the PolygonMesh if the PolyMeshType is SimpleMesh. For any other PolyMeshType, the N surface density value will be used as the column size.
因此,如果您将原始代码更改为 M=2/N=4,您应该会得到更好的结果。
PolygonMesh acPolyMesh = new PolygonMesh();
acPolyMesh.MSize = 2;
acPolyMesh.NSize = 4;
M x N 应该给出通过 AppendVertex 添加的顶点数。在您的原始代码中,4x4=16,但您只添加了 8,因此所有剩余的点都保留为 0,0,0(原点),导致您报告的问题。
关于c# - 在 AutoCAD (C#) 中绘制带网格的盒子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32461586/