删除选中图层中的所有实体

//函数中的参数strLayerName :图层名;objIds :为该图层中所有实体的Id集合

AcDbObjectIdArray EntIntLayer(CString strLayerName, AcDbObjectIdArray objIds)
{
//获得此图层空间内的所有实体
TCHAR *pValue = new TCHAR(strLayerName.GetLength() + 1);
_tcscpy(pValue, strLayerName);
//建立一个选择集来选取多段线实体
resbuf *resTmp = acutBuildList(8, pValue, RTDXF0, _T("LWPOLYLINE"), 0);
//resTmp->resval.rstring = pValue;//分配一个和pValue相当的内存给结果缓冲区
ads_name ent;
int nRs = acedSSGet(_T("_X"), NULL, NULL ,resTmp,ent);
if (RTNORM != nRs)
{
return false;
}
long ssLength;
if (acedSSLength(ent, &ssLength) != RTNORM)
{
acedSSFree(ent);
}
int ret;
AcDbObjectId objId;
for (int i=0; i<ssLength; ++i)
{
ads_name name;
ret = acedSSName(ent, i, name);
if (RTNORM != ret)
{
return false;
}
Acad::ErrorStatus es = acdbGetObjectId(objId, name);
if (Acad::eOk != es)
{
acedSSFree(name);
return false;
}
AcDbEntity *pEnt;
Acad::ErrorStatus ed = acdbOpenAcDbEntity(pEnt, objId, ZcDb::kForWrite);
pEnt->erase();
pEnt->close();
objIds.append(objId);
}
acutRelRb(resTmp);
acedSSFree(ent);
return objIds;
}

原文地址:https://www.cnblogs.com/pengjun-shanghai/p/4786303.html