|
[code]void cmdSweep()
{
ads_point pt;
ads_name ent;
AcDbObjectId objId, pathId;
Acad::ErrorStatus es;
if (acedEntSel(_T("\nSelect curve or region to sweep: "), ent, pt) != RTNORM)
return;
if (acdbGetObjectId(objId, ent) != Acad::eOk) //ads_name-->AcDbObjectId
return;
if (acedEntSel(_T("\nSelect sweep path: "), ent, pt) != RTNORM)
return;
if (acdbGetObjectId(pathId, ent) != Acad::eOk) //ads_name-->AcDbObjectId
return;
AcDbDatabase* pDB = objId.database();
AcDb3dSolid* solid = new AcDb3dSolid;
AcDbEntity* pSweepEnt;
AcDbCurve* path;
if ((es = acdbOpenObject(path, pathId, AcDb::kForRead)) == Acad::eOk)
{
if ((es = acdbOpenObject(pSweepEnt, objId, AcDb::kForRead)) == Acad::eOk)
{
AcDbSweepOptions sweepOpts;
sweepOpts.setAlignStart(true);
sweepOpts.setMiterOption(AcDbSweepOptions::kDefaultMiter);
solid->setDatabaseDefaults(pDB);
es = solid->createSweptSolid(pSweepEnt, path, sweepOpts);
if (!es)
{
es = postToDb(solid, pSweepEnt->database());
if (!es)
solid->close();
else
delete solid;
}
pSweepEnt->close();
}
path->close();
}
}
Acad::ErrorStatus postToDb(AcDbEntity* ent, AcDbDatabase *pDB) {
AcDbObjectId IdModelSpace = acdbSymUtil()->blockModelSpaceId(pDB);
AcDbBlockTableRecord* model;
Acad::ErrorStatus es;
if ((es = acdbOpenObject(model, IdModelSpace, AcDb::kForWrite)) == Acad::eOk)
{
es = model->appendAcDbEntity(ent);
model->close();
}
return es;
}[/code] |
|