2015-09-08 53 views
2

我一直在玩AutoCAD API的PolygonMesh類。我想用網格繪製一個簡單的框。我寫了一個簡單的方法來查看PolygonMesh的行爲方式用AutoCAD中的網格繪製一個框(C#)

[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(); 
    } 
} 

我期望的方法是繪製一個簡單的塊。相反,我得到一個塊,但也有行會又回到了原點:

What it's currently doing

如何改變這種方法,這樣,它只是繪製盒呢?

What I want

此外,如果有人可以解釋值M和N相對於網格,這將是真棒。

回答

2

從AutoCAD ObjectARX的幫助文件:

PolygonMesh.MSize

訪問在M方向的頂點數量。這是 頂點的數量,如果 PolyMeshType是SimpleMesh,將用於構成PolygonMesh中的M行。對於任何其他PolyMeshType,表面密度值將用作行大小。

PolygonMesh.NSize

訪問在N方向上的頂點數。如果PolyMeshType是SimpleMesh,這是 頂點的數量,這些頂點將用於構成PolygonMesh 中的N列。對於任何其他PolyMeshType,N 曲面密度值將用作列大小。

所以如果你改變原來的代碼爲M = 2/N = 4,你應該得到一個更好的結果。

PolygonMesh acPolyMesh = new PolygonMesh(); 
acPolyMesh.MSize = 2; 
acPolyMesh.NSize = 4; 

並且M×N應該給出通過AppendVertex添加的頂點的數量。在您的原始代碼中,4x4 = 16,但您只添加了8,因此所有剩餘的點都保留爲0,0,0(原點),導致您報告的問題。

+0

這是完美的,非常感謝! –