- UID
- 15750
- 积分
- 69
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-11-17
- 最后登录
- 1970-1-1
|
发表于 2006-7-21 16:59:43
|
显示全部楼层
//-----------------------------------------------------------------------------
// This is command 'CREATE, by HongxianQin [2005-4-13], Developer Department, AutoCAD
void Bpucreate()
{
AcDbBlockTable *pBlkTable;
AcDbBlockTableRecord* pBlkTableRecord;
acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTable,AcDb::kForRead);
pBlkTable->getAt(ACDB_MODEL_SPACE,pBlkTableRecord,AcDb::kForWrite);
pBlkTable->close();
AcGePoint2dArray ptArray;
AcDbPolyline* pPoly;
AcDbObjectId idExtrude;
AcGePoint2d ptInput;
AcGePoint2d ptVertex;
Acad::ErrorStatus es;
for(int j = 0;j<4;j++)
{
acedGetPoint(NULL,"选择点\n",asDblArray(ptInput));
ptArray.append(ptInput);
}
pPoly = new AcDbPolyline(4);
for(int i = 0; i < ptArray.length(); i++)
{
ptVertex = ptArray.at(i);
pPoly->addVertexAt(i, ptVertex);
}
pPoly->setClosed(Adesk::kTrue);
es = pBlkTableRecord->appendAcDbEntity(idExtrude, pPoly);
pBlkTableRecord->close();
pPoly->close();
}
void CreateSolidExtrude(AcDbPolyline* pPoly,AcDbObjectId &idExtrude,double height,double taper)
{
AcDbBlockTable *pBlkTable;
AcDbBlockTableRecord* pBlkTableRecord;
Acad::ErrorStatus es;
AcDbVoidPtrArray lines;
AcDbVoidPtrArray regions;
//AcDbObject *pObj = NULL;
//AcDbObjectId idEnt;
//ads_name ename;
//ads_point pickpt;
acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTable,AcDb::kForRead);
pBlkTable->getAt(ACDB_MODEL_SPACE,pBlkTableRecord,AcDb::kForWrite);
pBlkTable->close();
//acedEntSel("\nSelect a polygon: ",ename, pickpt);
//acdbGetObjectId(idEnt, ename);
//AcDbEntity *pEnt;
//acdbOpenObject(pPoly,idEnt,AcDb::kForWrite);
pPoly->explode(lines);
// Create a region from the set of lines.
AcDbRegion::createFromCurves(lines, regions);
//assert(regions.length() == 1);
AcDbRegion *pRegion = AcDbRegion::cast((AcRxObject*)regions[0]);
//assert(pRegion != NULL);
// Extrude the region to create a solid.
AcDb3dSolid *pSolid = new AcDb3dSolid;
pSolid->extrude(pRegion, height, taper);
// acedGetVar()
/*
for (int i = 0; i < lines.length(); i++) {
delete (AcRxObject*)lines;
}
for (i = 0; i < regions.length(); i++) {
delete (AcRxObject*)regions;
}*/
pSolid->setPropertiesFrom(pPoly);
es = pBlkTableRecord->appendAcDbEntity(idExtrude, pSolid);
//pSolid->draw();
/////////////////////////////////////////
pBlkTableRecord->close();
pPoly->close();
pSolid->close();
}
//-----------------------------------------------------------------------------
// This is command 'CREATESD, by HongxianQin [2005-4-13], Developer Department, AutoCAD
void Bpucreatesd()
{
AcDbBlockTable *pBlkTable;
AcDbBlockTableRecord* pBlkTableRecord;
AcDbPolyline* pPoly= NULL;
AcDbObjectId idExtrude;
double height= 50.0;
Acad::ErrorStatus es;
AcDbVoidPtrArray lines;
AcDbVoidPtrArray regions;
AcDbObject *pObj = NULL;
AcDbObjectId idEnt;
ads_name ename;
ads_point pickpt;
acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTable,AcDb::kForRead);
pBlkTable->getAt(ACDB_MODEL_SPACE,pBlkTableRecord,AcDb::kForWrite);
pBlkTable->close();
acedEntSel("\nSelect a polygon: ",ename, pickpt);
acdbGetObjectId(idEnt, ename);
//AcDbEntity *pEnt;
acdbOpenObject(pPoly,idEnt,AcDb::kForWrite);
pPoly->explode(lines);
// Create a region from the set of lines.
AcDbRegion::createFromCurves(lines, regions);
//assert(regions.length() == 1);
AcDbRegion *pRegion = AcDbRegion::cast((AcRxObject*)regions[0]);
//assert(pRegion != NULL);
// Extrude the region to create a solid.
AcDb3dSolid *pSolid = new AcDb3dSolid;
pSolid->extrude(pRegion, height, 0.4);
/*
for (int i = 0; i < lines.length(); i++) {
delete (AcRxObject*)lines;
}
for (i = 0; i < regions.length(); i++) {
delete (AcRxObject*)regions;
}*/
pSolid->setPropertiesFrom(pPoly);
es = pBlkTableRecord->appendAcDbEntity(idExtrude, pSolid);
//pSolid->draw();
/////////////////////////////////////////
pBlkTableRecord->close();
pPoly->close();
pSolid->close();
}
//-----------------------------------------------------------------------------
// This is command 'SOLIDTEST, by HongxianQin [2005-4-13], Developer Department, AutoCAD
void BpusolidTest()
{
//创建轮廓线
AcGePoint2dArray ptArray;
AcDbPolyline* pPoly;
AcDbObjectId idPoly1,idPoly2;
AcGePoint2d ptInput;
AcGePoint2d ptVertex;
for(;acedGetPoint(NULL,"选择点\n",asDblArray(ptInput))==RTNORM;)
{
ptArray.append(ptInput);
}
pPoly = new AcDbPolyline(ptArray.length());
for(int i = 0; i < ptArray.length(); i++)
{
ptVertex = ptArray.at(i);
pPoly->addVertexAt(i, ptVertex);
}
pPoly->setClosed(Adesk::kTrue);
addToModelSpace(idPoly1,pPoly);
//创建轮廓线2
AcDbPolyline *pPloyOut;
acdbOpenObject(pPloyOut, idPoly1, AcDb::kForRead);
// Now generate an ellipse offset by 0.5 drawing units.
//
AcDbVoidPtrArray curves;
pPloyOut->getOffsetCurves(20.0, curves);
pPloyOut->close();
addToModelSpace(idPoly2, (AcDbEntity*)curves[0]);
//
acdbOpenObject(pPoly,idPoly1,AcDb::kForWrite);
AcDbObjectId idSolid1,idSolid2;
CreateSolidExtrude(pPoly,idSolid1,500.0,0.0);
acdbOpenObject(pPloyOut,idPoly2,AcDb::kForWrite);
CreateSolidExtrude(pPloyOut,idSolid2,500.0,0.5);
AcDb3dSolid *pSolid ;
acdbOpenObject(pSolid,idSolid2,AcDb::kForWrite);
AcGeMatrix3d mat;
mat.setTranslation(AcGeVector3d(0,0,500.0));
pSolid->transformBy(mat);
pSolid->close();
}
Acad::ErrorStatus
addToModelSpace(AcDbObjectId &objId, AcDbEntity* pEntity)
{
AcDbBlockTable *pBlockTable;
AcDbBlockTableRecord *pSpaceRecord;
acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pBlockTable, AcDb::kForRead);
pBlockTable->getAt(ACDB_MODEL_SPACE, pSpaceRecord,
AcDb::kForWrite);
pSpaceRecord->appendAcDbEntity(objId, pEntity);
pBlockTable->close();
pEntity->close();
pSpaceRecord->close();
return Acad::eOk;
} |
|