TA的每日心情![](source/plugin/dsu_paulsign/img/emot/kx.gif) | 开心 昨天 15:23 |
---|
签到天数: 69 天 [LV.6]常住居民II
管理员
- 积分
- 2704
|
// Add an entity to the current database.
Acad::ErrorStatus postToDb(AcDbEntity* pEnt)
{
Acad::ErrorStatus es, es2;
AcDbBlockTable* pBlockTable = 0;
AcDbBlockTableRecord* pSpaceRecord = 0;
if (!pEnt)
return Acad::eNullEntityPointer;
AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase();
if ((es = pDb->getBlockTable(pBlockTable, AcDb::kForRead)) != Acad::eOk)
return es;
if ((es = pBlockTable->getAt(ACDB_MODEL_SPACE, pSpaceRecord, AcDb::kForWrite)) == Acad::eOk)
{
AcDbObjectId objId;
es = pSpaceRecord->appendAcDbEntity(objId, pEnt);
es2 = pSpaceRecord->close();
if (es == Acad::eOk)
{
es2 = pEnt->downgradeOpen();
es2 = pEnt->draw();
pEnt->close();
}
}
es2 = pBlockTable->close();
return es;
}
void CreateCylinder()
{
double diameter=50.0;
AcGePoint3d p1(0,0,0), p2(0,0,100);
AcGeVector3d v12(p2-p1);
AcGePoint3d ptMid = p1 + v12/2;
Acad::ErrorStatus es;
AcDb3dSolid *cylinder = new AcDb3dSolid();
cylinder->setDatabaseDefaults(); // set current color, layer and linetype
double height = v12.length(), radius= diameter/2;
es = cylinder->createFrustum(height, radius, radius, radius);
// createFrustum() creates a cylinder with midpoint at 0,0,0 and rotation axis=Z
// So we have to align the cylinder:
AcGeVector3d vx, vy, vz(v12 / height);
vx = vz.perpVector();
vy = vz.crossProduct(vx);
AcGeMatrix3d mat;
mat.setCoordSystem(ptMid, vx, vy, vz);
es = cylinder->transformBy(mat);
es = postToDb(cylinder);
} |
|