|
須要頭文件#include " dbhatch.h "lua
void ZffCHAP2AddHatch()
{
// 提示用戶選擇填充邊界
ads_name ss;
int rt = acedSSGet(NULL, NULL, NULL, NULL, ss);
AcDbObjectIdArray objIds;
// 初始化填充邊界的ID數組
if (rt == RTNORM)
{
long length;
acedSSLength(ss, &length);
for (int i = 0; i < length; i++)
{
ads_name ent;
acedSSName(ss, i, ent);
AcDbObjectId objId;
acdbGetObjectId(objId, ent);
objIds.append(objId);
}
}
acedSSFree(ss); // 釋放選擇集
CCreateEnt::CreateHatch(objIds, "SOLID", true);
}
AcDbObjectId CCreateEnt::CreateHatch(AcDbObjectIdArray objIds,const char* patName, bool bAssociative)
{
Acad::ErrorStatus es;
AcDbHatch *pHatch = new AcDbHatch();
// 設置填充平面
AcGeVector3d normal(0, 0, 1);
pHatch->setNormal(normal);
pHatch->setElevation(0);
// 設置關聯性
pHatch->setAssociative(bAssociative);
// 設置填充圖案
pHatch->setPattern(AcDbHatch::kPreDefined, patName);
// 添加填充邊界
es = pHatch->appendLoop(AcDbHatch::kExternal, objIds);
// 顯示填充對象
es = pHatch->evaluateHatch();
// 添加到模型空間
AcDbObjectId hatchId;
hatchId = CCreateEnt::PostToModelSpace(pHatch);
// 若是是關聯性的填充,將填充對象與邊界綁定,以便使其能得到邊界對象修改的通知
if (bAssociative)
{
AcDbEntity *pEnt;
for (int i = 0; i < objIds.length(); i++)
{
es = acdbOpenAcDbEntity(pEnt, objIds[i],AcDb::kForWrite);
if (es == Acad::eOk)
{
// 添加一個永久反應器
pEnt->addPersistentReactor(hatchId);
pEnt->close();
}
}
}
return hatchId;
}
appendLoop函數定義爲:3d
Acad::ErrorStatus appendLoop(Adesk::Int32 loopType,const AcDbObjectIdArray& dbObjIds);
第一個參數:邊界類型;第二個參數:邊界實體的id數組code |
|