Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用网格绘制实体长方体_C#_Mesh_Autocad - Fatal编程技术网

C# 使用网格绘制实体长方体

C# 使用网格绘制实体长方体,c#,mesh,autocad,C#,Mesh,Autocad,我正在尝试使用C#在AutoCAD中以编程方式绘制实心长方体/矩形。我很接近,但网格的顶部和底部不是实心的。下面是我绘制网格的方法 [CommandMethod("TESTSIMPLEMESH")] public void TestSimpleMesh() { // Get the current document and database, and start a transaction Database _database = HostApplicationServices.

我正在尝试使用C#在AutoCAD中以编程方式绘制实心长方体/矩形。我很接近,但网格的顶部和底部不是实心的。下面是我绘制网格的方法

[CommandMethod("TESTSIMPLEMESH")]
public void TestSimpleMesh()
{
    // Get the current document and database, and start a transaction
    Database _database = HostApplicationServices.WorkingDatabase;
    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();

        /*
         * M indicates No of rows and N indicates No of columns, visualize it as Grid
         * So to have cube, we need two rows of vertices and 4 colomns of vertices
         * Now we need to close last column of vertices with first column of vertices that makes a simple cube or else planar surface with facets.
         */
        acPolyMesh.MSize = 2;
        acPolyMesh.NSize = 4;
        acPolyMesh.MakeNClosed(); //This function sets the PolygonMesh to be closed in the N direction. This means that the mesh will be treated as continuous from the last row on to the first row.

        // 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();
    }
}
结果如下

在你鸟瞰它之前,它看起来很好


因此,侧面是实心的,但顶部和底部不是。如何更改上述方法以使所有6条边都是实心的?

如果需要实心,请使用
Solid3d.CreateBox
而不是
polygomesh

如果需要网格,则应使用
SubDMesh
类,而不是
PolygonMesh
,后者会艰难地创建旧网格

[CommandMethod("CREATESUBDMESH")]
public void CreateSubDMesh()
{
  Document doc = Application.DocumentManager.MdiActiveDocument;
  Database db = doc.Database;
  Editor ed = doc.Editor;
  using (Transaction tr = db.TransactionManager.StartTransaction())
  {
    var mesh = new SubDMesh();
    mesh.Setbox(100, 100, 100, 1, 1, 1, 0);
    var currentSpace = (BlockTableRecord) tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
    currentSpace.AppendEntity(mesh);
    tr.AddNewlyCreatedDBObject(mesh, true);
    tr.Commit();
  }
}

看看这个:它实际上可以完美地工作。问题是,正如您当前所拥有的,它总是在原点(0,0,0)处绘制。我可以指定在哪里绘制它吗?创建后可以移动它:
mesh.TransformBy(Matrix3d.Displacement(newvector3d(100200300))明白了,我把它编码好了,它几乎可以工作了。我的转换不太正常。框的哪个点与原点对齐?框以原点为中心。