完整的实现代码:
static void AAAMyGroupMyCommand () {
// Put your command code here
acutPrintf(_T("\\nHello World!"));
//创建一个简单的多边形网格
AcGePoint3dArray ptArr;
ptArr.setLogicalLength(8);
for (int i = 0; i < 8; i++) //在X-Y平面上产生8个点
{
ptArr[i].set((double)(i / 2), (double)(i % 2), 0.0);
}
//默认构造函数。构造一个带有线型生成off的开放折线,并初始化开始和结束宽度到0.0,凸起到0.0,仰角到0.0,类型到AcDb::k2dSimplePoly,法线到(0,0,1),厚度到0.0。
AcDb2dPolyline *pNewPline = new AcDb2dPolyline(AcDb::k2dSimplePoly, ptArr, 0.0, Adesk::kTrue);
pNewPline->setColorIndex(100);
//没有任何参数的多边形网格构造函数
AcDbPolygonMesh *pMesh = new AcDbPolygonMesh();
pMesh->setMSize(2); //设置多边形在M方向上的顶点数为2
pMesh->setNSize(8); //设置多边形在N方向上的顶点数为8
pMesh->makeMClosed(); //这个函数设置多边形在M方向上闭合。
pMesh->makeNClosed(); //这个函数设置多边形在N方向上闭合。
AcDbVoidPtrArray arr;
arr.append(pMesh);
//获得指向块表的指针
AcDbBlockTable *pBlockTable;
acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pBlockTable, AcDb::kForRead);
//获得指向块表记录(模型空间)的指针
AcDbBlockTableRecord *pBlockTableRecord;
pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite);
pBlockTable->close();
AcDbObjectId plineObjId;
//将pNewPline添加到数据库和块表记录中。如果操作成功,则将plineObjId设置为新添加实体的AcDbObjectId。
pBlockTableRecord->appendAcDbEntity(plineObjId, pNewPline);
AcDbObjectIterator *pVertIter = pNewPline->vertexIterator();//创建一个新的AcDbObjectIterator集,用于在折线的顶点上迭代
AcDb2dVertex *pVertex;
AcGePoint3d location;
AcDbObjectId vertexObjId;
for (int vertexNumber = 0; !pVertIter->done(); vertexNumber++, pVertIter->step())
{
vertexObjId = pVertIter->objectId();
acdbOpenObject(pVertex, vertexObjId, AcDb::kForRead);//指向打开对象的输出指针pVertex,输入要打开对象的对象ID:vertexObjId
location = pVertex->position();
pVertex->close();
//AcDbPolygonMeshVertex类表示AutoCAD中多边形网格内的顶点。
AcDbPolygonMeshVertex* polyVertex = new AcDbPolygonMeshVertex(pVertex->position());
pMesh->appendVertex(polyVertex);
polyVertex->close();
}
delete pVertIter;
pBlockTableRecord->appendAcDbEntity(pMesh);
pBlockTableRecord->close();
pNewPline->close();
pMesh->close();
acutPrintf(_T("\\nHello World2!"));
}
效果:
参考文献:
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容