|
acDocManager->lockDocument(acDocManager->curDocument());
CDwgDatabaseUtil::setVar(_T("cmdecho"), 0); // 关闭回显
acedCommand(RTSTR, _T("undo"), RTSTR, _T("be"), RTNONE);
ads_name ssName;
int rt = acedSSGet(_T("X"), NULL, NULL, NULL, ssName);
if (rt != RTNORM)
{
return;
}
std::vector<CString> ssentVec;
long length;
acedSSLength(ssName, &length);
acedSetStatusBarProgressMeter(_T("◎正在删除重覆实体,等稍等!"), 0, 100);
DWORD dwCount = ::GetTickCount();
for (int i = 0; i < length; i++)
{
// 100毫秒更新一次
if(::GetTickCount() - dwCount > 100)
{
acedSetStatusBarProgressMeterPos((int) (i * 100.0 / length));
dwCount = ::GetTickCount();
}
ads_name ent;
acedSSName(ssName, i, ent);
struct resbuf *rbEnt; // 保存实体数据的结果缓冲区
struct resbuf *rb; // 用于遍历rbEnt的结果缓冲区
rbEnt = acdbEntGet(ent); // 从entName获得保存实体数据的结果缓冲区
rb = rbEnt;
CString entname, typa, s10Ptx, s10Pty, s10Ptz, s11Ptx, s11Pty, s11Ptz, svNum;
std::vector<CString> entVec;
while (rb != NULL)
{
switch (rb->restype)
{
case 0: // 对象类型
typa.Format(_T("%s"), rb->resval.rstring);
entVec.push_back(typa);
break;
case 10: // 起点(顶点)坐标
s10Ptx.Format(_T("%.2f"), rb->resval.rpoint[X]);
s10Pty.Format(_T("%.2f"), rb->resval.rpoint[Y]);
s10Ptz.Format(_T("%.2f"), rb->resval.rpoint[Z]);
entVec.push_back(s10Ptx);
entVec.push_back(s10Pty);
entVec.push_back(s10Ptz);
break;
case 11: // 终点坐标
s11Ptx.Format(_T("%.2f"), rb->resval.rpoint[X]);
s11Pty.Format(_T("%.2f"), rb->resval.rpoint[Y]);
s11Ptz.Format(_T("%.2f"), rb->resval.rpoint[Z]);
entVec.push_back(s11Ptx);
entVec.push_back(s11Pty);
entVec.push_back(s11Ptz);
break;
case 93: // 顶点数目
svNum.Format(_T("%f"), rb->resval.rreal);
entVec.push_back(svNum);
break;
default:
break;
}
rb = rb->rbnext; // 切换到下一个节点
}
if (rbEnt != NULL)
{
acutRelRb(rbEnt);
}
CString entVeclist = CStringUtil::Join(entVec, _T(","));
ssentVec.push_back(entVeclist);
}
acedRestoreStatusBar();
CString fistNaem = ssentVec[0]; // 首个
ssentVec.erase(ssentVec.begin()); // 删除第一元素
int index = 0;
int len = ssentVec.size();
int num = 0;
while (len > 0)
{
for (int i = 0; i < ssentVec.size(); i++)
{
CString temp = ssentVec<i>;
if (_tcscmp(fistNaem, temp) == 0)
{
ads_name ent;
acedSSName(ssName, num, ent);
AcDbObjectId entId;
acdbGetObjectId(entId, ent);
CEntityUtil::Erase(entId);
index++;
}
}
num = num + 1;
fistNaem = ssentVec[0];
ssentVec.erase(ssentVec.begin());
len = ssentVec.size();
}
acedSSFree(ssName);
acutPrintf(_T("\n共删除 %d 个重覆物体"), index);
acDocManager->unlockDocument(acDocManager->curDocument()); |
|