|
//将实体加入到模型数据库中
int addEntityToModelSpace(Acad::ErrorStatus& es,AcDbObjectId& entityId,AcDbEntity *pEntity)
{
//创建块表
AcDbBlockTable *pBlockTable;
acdbHostApplicationServices() -> workingDatabase()
->getSymbolTable(pBlockTable,AcDb::kForRead);
//创建块表记录
AcDbBlockTableRecord *pBlockTableRecord;
pBlockTable ->getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForWrite);
pBlockTable ->close();
//向模型数据库中追回实体记录
pBlockTableRecord ->appendAcDbEntity(entityId,pEntity);
pBlockTableRecord ->close();
pEntity->close();
return 0;
}
// This is command 'TEST'
void Test()
{
// TODO: Implement the command
Acad::ErrorStatus es = Acad::eOk;
/*
//*************************以选择实体方式创建区域图形******************
ads_name entName;
ads_point pickpt;
acedEntSel("/n请选择一个闭合图形:",entName,pickpt);
AcDbObjectId objId;
acdbGetObjectId(objId,entName);
AcDbObject *pObj=NULL;
acdbOpenObject( pObj, objId, AcDb::kForRead );
//创建一个面域
AcDbVoidPtrArray curveSegments;
curveSegments.append(pObj);
//***************************************************************
*/
/*
//*************************以选择集方式创建区域图形******************
ads_name ssName;
acedSSGet(NULL,NULL,NULL,NULL,ssName);
//获取选择集中的实体个数
long NumOfSS;//选择集的个数
acedSSLength(ssName,&NumOfSS);
//AcDbObjectIdArray SSIdArray;
AcDbVoidPtrArray curveSegments;
for (long i=0;i<NumOfSS;i++)
{
ads_name temptest;
acedSSName(ssName,i,temptest);
AcDbObjectId objId;
es = acdbGetObjectId(objId,temptest);
AcDbObject *pObj = NULL;
acdbOpenObject(pObj,objId,AcDb::kForRead);
curveSegments.append(pObj);
}
*/
/*
***********************生成 一个正方体*************************
AcDbLine *pLine1;
pLine1 = new AcDbLine(AcGePoint3d(0,0,0),AcGePoint3d(2000,0,0));
curveSegments.append(pLine1);
pLine1 = new AcDbLine(AcGePoint3d(2000,0,0),AcGePoint3d(2000,2000,0));
curveSegments.append(pLine1);
pLine1 = new AcDbLine(AcGePoint3d(2000,2000,0),AcGePoint3d(0,2000,0));
curveSegments.append(pLine1);
pLine1 = new AcDbLine(AcGePoint3d(0,2000,0),AcGePoint3d(0,0,0));
curveSegments.append(pLine1);
*****************************************************************
*/
//生成一个圆
AcDbCircle *pCircle = new AcDbCircle(AcGePoint3d::kOrigin, AcGeVector3d::kZAxis, 1000);
//创建一个面域
AcDbVoidPtrArray curveSegments;
curveSegments.append(pCircle);
AcDbVoidPtrArray regions;
es = AcDbRegion::createFromCurves(curveSegments,regions);
if (es != Acad::eOk)
{
delete pCircle;
//delete pLine1;
return;
}
delete pCircle;
//delete pLine1;
AcDbRegion *pRegion = (AcDbRegion *)regions[0];
//生成拉伸路径
AcDbLine *pLine = new AcDbLine(AcGePoint3d::kOrigin,
AcGePoint3d(0,0,1000));
//加入到模型数据库中
AcDbObjectId lineId;
if (addEntityToModelSpace(es,lineId, pLine))
{
delete pRegion;
delete pLine;
return;
}
pLine->close();
//拉伸路径需要以读方式来打开
es = acdbOpenObject(pLine, lineId, AcDb::kForRead);
if (es != Acad::eOk)
{
delete pRegion;
return;
}
//拉伸成Solid;
AcDb3dSolid *pSolid = new AcDb3dSolid();
es = pSolid->extrudeAlongPath(pRegion, pLine);
delete pRegion;
pLine->close();
if (es != Acad::eOk)
{
delete pSolid;
return;
}
//将Solid实体加入到模型数据库中
AcDbObjectId solidId;
if (addEntityToModelSpace(es, solidId, pSolid))
{
delete pSolid;
return;
}
pSolid->close();
} |
|