几个实用的插件
删除重覆实体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);
s10Pty.Format(_T("%.2f"), rb->resval.rpoint);
s10Ptz.Format(_T("%.2f"), rb->resval.rpoint);
entVec.push_back(s10Ptx);
entVec.push_back(s10Pty);
entVec.push_back(s10Ptz);
break;
case 11: // 终点坐标
s11Ptx.Format(_T("%.2f"), rb->resval.rpoint);
s11Pty.Format(_T("%.2f"), rb->resval.rpoint);
s11Ptz.Format(_T("%.2f"), rb->resval.rpoint);
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; // 首个
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;
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;
ssentVec.erase(ssentVec.begin());
len = ssentVec.size();
}
acedSSFree(ssName);
acutPrintf(_T("\n共删除 %d 个重覆物体"), index);
acDocManager->unlockDocument(acDocManager->curDocument());
本帖最后由 gzxl 于 2015-10-6 00:20 编辑
自动断面
Sorry源码不上传了 gzxl 发表于 2015-10-5 21:49
高程点移位
请问版主 CDwgDatabaseUtil这个类是怎么来的啊? 图面检查和高程点移位楼主能不能发一个(295481682@qq.com),谢谢 本帖最后由 gzxl 于 2015-10-5 23:47 编辑
图面检查
文本加减乘除
acDocManager->lockDocument(acDocManager->curDocument());
TCHAR szKword;
acedInitGet(NULL, _T("A B C D"));
int nReturn = acedGetKword(_T("\n输入选项[加(A)/减(B)/乘(C)/除(D)]:"), szKword);
if (nReturn == RTNORM || nReturn == RTKWORD)
{
std::vector<AcRxClass*> descs;
descs.push_back(AcDbText::desc());
descs.push_back(AcDbMText::desc());
AcDbEntity *pEnt = NULL;
AcGePoint3d pickPoint;
if (CSelectUtil::PromptSelectEntity(_T("\n请点选首个文本数字作为开头:"), descs, pEnt, pickPoint))
{
CString strName;
if (pEnt->isKindOf(AcDbText::desc()))
{
AcDbText *pText = AcDbText::cast(pEnt);
strName = pText->textString();
// 截取字符串中的纯数字
sscanf(strName, _T("%* %"), strName);
}
else
{
AcDbMText *pMText = AcDbMText::cast(pEnt);
TCHAR *chaName;
chaName = pMText->contents();
CString strName(chaName);
int n = strName.ReverseFind(';');
strName = strName.Right(strName.GetLength() - n - 1);
sscanf(strName, _T("%* %"), strName);
acutDelString(chaName);
}
double firstNum = CConvertUtil::ToDouble(strName);
AcDbObjectIdArray entIds;
if (CSelectUtil::PromptSelectEnts(_T("\n选择其它文本数字<可单选或多选>:"), descs, entIds))
{
for (int i = 0; i < entIds.length(); i++)
{
AcDbEntity *pNEnt = NULL;
if (acdbOpenObject(pNEnt, entIds, AcDb::kForRead) == Acad::eOk)
{
if (pNEnt->isKindOf(AcDbText::desc()))
{
AcDbText *pText = AcDbText::cast(pNEnt);
strName = pText->textString();
sscanf(strName, _T("%* %"), strName);
}
else
{
AcDbMText *pMText = AcDbMText::cast(pNEnt);
TCHAR *chaName;
chaName = pMText->contents();
CString strName(chaName);
int n = strName.ReverseFind(';');
strName = strName.Right(strName.GetLength() - n - 1);
sscanf(strName, _T("%* %"), strName);
acutDelString(chaName);
}
}
double secondNum = CConvertUtil::ToDouble(strName);
if (_tcscmp(szKword, _T("A")) == 0)
{
firstNum = firstNum + secondNum;
}
else if (_tcscmp(szKword, _T("B")) == 0)
{
firstNum = firstNum - secondNum;
}
else if (_tcscmp(szKword, _T("C")) == 0)
{
firstNum = firstNum * secondNum;
}
else
{
firstNum = firstNum / secondNum;
}
pNEnt->close();
}
CString firstStr = CConvertUtil::ToString(firstNum, 3);
ads_point adsPoint;
if (acedGetPoint(NULL, _T("拾取标注点:"), adsPoint) == RTNORM)
{
AcGePoint3d pt = asPnt3d(adsPoint);
AcDbText *pText = new AcDbText(pt, firstStr, AcDbObjectId::kNull, 10, 0);
pText->setColorIndex(1);
CDwgDatabaseUtil::PostToModelSpace(pText);
}
pEnt->close();
}
}
}
acDocManager->unlockDocument(acDocManager->curDocument());
修改颜色acDocManager->lockDocument(acDocManager->curDocument());
ads_name ss, en;
if (acedSSGet(NULL, NULL, NULL, NULL, ss) != RTNORM)
{
return;
}
int colorindex;
acedSetColorDialog(colorindex, true, 1);
long len;
if (RTNORM == acedSSLength(ss, &len))
{
for (int i = 0; i < len; i++)
{
acedSSName(ss, i, en);
AcDbObjectId id;
acdbGetObjectId(id, en);
AcDbEntity *pEnt;
acdbOpenObject(pEnt, id, AcDb::kForWrite);
AcCmColor colors;
colors.setColorIndex(colorindex);
if (pEnt->isKindOf(AcDbBlockReference::desc()))
{
AcDbBlockReference *pBlk = AcDbBlockReference::cast(pEnt);
ChangeColor(pBlk, colors);
}
pEnt->setColor(colors);
pEnt->close();
}
}
acedSSFree(ss);
acDocManager->unlockDocument(acDocManager->curDocument());
static void ChangeColor(AcDbBlockReference *pBlk, AcCmColor col)
{
AcDbObjectId blkId = pBlk->blockTableRecord();
AcDbBlockTableRecord *pBlkRcd;
acdbOpenObject(pBlkRcd, blkId, AcDb::kForWrite);
AcDbBlockTableRecordIterator *pItr;
pBlkRcd->newIterator(pItr);
for (pItr->start(); !pItr->done(); pItr->step())
{
AcDbEntity *pEnt1;
pItr->getEntity(pEnt1, AcDb::kForWrite);
pEnt1->setColor(col);
if (pEnt1->isKindOf(AcDbBlockReference::desc()))
{
AcDbBlockReference *pBlk1 = AcDbBlockReference::cast(pEnt1);
ChangeColor(pBlk1, col);
}
pEnt1->close();
}
delete pItr;
pBlkRcd->close();
AcDbObjectIterator *attIt = pBlk->attributeIterator();
for (attIt->start(); !attIt->done(); attIt->step())
{
AcDbAttribute *pAtt = NULL;
AcDbObjectId attrObjId;
attrObjId = attIt->objectId();
Acad::ErrorStatus es = acdbOpenObject(pAtt, attrObjId, AcDb::kForWrite);
if (es == Acad::eOk)
{
pAtt->setColor(col);
pAtt->close();
}
}
delete attIt;
pBlk->setColorIndex(0);
} 高程点移位
acDocManager->lockDocument(acDocManager->curDocument());
int iosmode = 0;
CDwgDatabaseUtil::GetVar(_T("osmode"), iosmode); // 获取捕捉状态值
CDwgDatabaseUtil::setVar(_T("osmode"), 0);// 设置捕获关
CDwgDatabaseUtil::setVar(_T("cmdecho"), 0); // 关闭回显
acedCommand(RTSTR, _T("undo"), RTSTR, _T("be"), RTNONE);
bool result = true;
AcGePoint3dArray ptArray;
ads_name ss;
// 建立缓冲区链表
AcDbObjectIdArray entIds;
struct resbuf *rb, *retRb;
CString myXdata = _T("202101");
rb = acutBuildList(RTDXF0, _T("INSERT"), 2, _T("gc200"), RTNONE);
if (CCassUtil::PromptSelectEnts(_T("X"), myXdata, rb, entIds))
{
long length = entIds.length();
for (int i = 0; i < length; i++)
{
AcDbEntity *pEnt = NULL;
if (acdbOpenObject(pEnt, entIds, AcDb::kForWrite) == Acad::eOk)
{
CString layerName = pEnt->layer(); //图层名
AcGePoint2d zxPt, ysPt; // 文本的左下角点、右上角点
AcDbBlockReference *pBlk = AcDbBlockReference::cast(pEnt);
AcGePoint3d pt3d = pBlk->position();
double ptz = pt3d.z;
AcDbObjectIterator *pAttrIter = pBlk->attributeIterator();
AcDbAttribute *pAttr = NULL;
AcDbObjectId attrObjId = NULL;
CString strHeight;
AcGePoint3d AlimPt, textPt;
attrObjId = pAttrIter->objectId();
acdbOpenObject(pAttr, attrObjId, AcDb::kForWrite);
strHeight = pAttr->textString();
double hh = pAttr->height(); // 文字高度
double ww = pAttr->widthFactor(); // 宽度比例系数
double ll = CTextUtil::getTextLength(strHeight, hh, ww); // 文字长度
AlimPt = pAttr->alignmentPoint(); // 对齐点
textPt = pAttr->position(); // 文本的位置点(左下角点)
AcGePoint3d yPt1 = CGePointUtil::PolarPoint(textPt, 0.0, ll); // 向右
AcGePoint3d yPt2 = CGePointUtil::PolarPoint(yPt1, CMathUtil::PI() * 0.5, hh); // 向上
zxPt = CConvertUtil::ToPoint2d(textPt); // 文本的位置点(左下角点)
ysPt = CConvertUtil::ToPoint2d(yPt2); // 文本的位置点(右上角点)
CViewUtil::Set(textPt, yPt2, 3);
retRb = acutBuildList(-4, _T("<NOT"), 2, _T("GC200"), -4, _T("NOT>"), RTNONE);
int rt = acedSSGet(_T("C"), asDblArray(zxPt), asDblArray(ysPt), retRb, ss);
if (rt != RTNORM)
{
pAttr->close();
delete pAttrIter;
pBlk->close();
pEnt->close();
acutRelRb(retRb);
acedSSFree(ss);
result = false;
continue;
}
else
{
acutRelRb(retRb);
acedSSFree(ss);
result = true;
}
AcGePoint2d ydPt1, ydPt2, xdPt1, xdPt2, xdPt3, xdPt4, xdPt5, xdPt6, xdPt7, xdPt8;
if (result)
{
// 设定向下移动限制
double xzLen = hh;
double yLen = 0;
while (yLen < xzLen)
{
yLen = yLen + hh * 0.25;
ydPt1 = CGePointUtil::PolarPoint(zxPt, CMathUtil::PI() * 1.5, yLen);
ydPt2 = CGePointUtil::PolarPoint(ysPt, CMathUtil::PI() * 1.5, yLen);
retRb = acutBuildList(-4, _T("<NOT"), 2, _T("GC200"), -4, _T("NOT>"), RTNONE);
int rt = acedSSGet(_T("C"), asDblArray(ydPt1), asDblArray(ydPt2), retRb, ss);
if (rt != RTNORM)
{
// 文本的位置点
AcGePoint3d setPosPt(ydPt1.x, ydPt1.y, ptz);
AcGePoint3d setAliPt = CGePointUtil::PolarPoint(setPosPt, CMathUtil::PI() * 0.5, hh * 0.5);
pAttr->setHorizontalMode(AcDb::kTextLeft); // 左对齐
pAttr->setVerticalMode(AcDb::kTextVertMid);// 左中
pAttr->setPosition(setPosPt);
pAttr->setAlignmentPoint(setAliPt);
acutRelRb(retRb);
acedSSFree(ss);
result = false;
break;
}
else
{
acutRelRb(retRb);
acedSSFree(ss);
result = true;
}
}
}
if (result)
{
// 设定向左移动限制
double yzLen = hh * 4;
double yLen = 0;
while (yLen < yzLen)
{
yLen = yLen + hh * 0.25;
xdPt1 = CGePointUtil::PolarPoint(ydPt1, CMathUtil::PI(), yLen);
xdPt2 = CGePointUtil::PolarPoint(ydPt2, CMathUtil::PI(), yLen);
retRb = acutBuildList(-4, _T("<NOT"), 2, _T("GC200"), -4, _T("NOT>"), RTNONE);
int rt = acedSSGet(_T("C"), asDblArray(xdPt1), asDblArray(xdPt2), retRb, ss);
if (rt != RTNORM)
{
AcGePoint3d setPosPt(xdPt1.x, xdPt1.y, ptz);
AcGePoint3d setAliPt = CGePointUtil::PolarPoint(setPosPt, CMathUtil::PI() * 0.5, hh * 0.5);
pAttr->setHorizontalMode(AcDb::kTextLeft); // 左对齐
pAttr->setVerticalMode(AcDb::kTextVertMid);// 左中
pAttr->setPosition(setPosPt);
pAttr->setAlignmentPoint(setAliPt);
acutRelRb(retRb);
acedSSFree(ss);
result = false;
break;
}
else
{
acutRelRb(retRb);
acedSSFree(ss);
result = true;
}
}
}
if (result)
{
// 设定向上移动限制
double yzLen = hh * 2;
double yLen = 0;
while (yLen < yzLen)
{
yLen = yLen + hh * 0.25;
xdPt3 = CGePointUtil::PolarPoint(xdPt1, CMathUtil::PI() * 0.5, yLen);
xdPt4 = CGePointUtil::PolarPoint(xdPt2, CMathUtil::PI() * 0.5, yLen);
retRb = acutBuildList(-4, _T("<NOT"), 2, _T("GC200"), -4, _T("NOT>"), RTNONE);
int rt = acedSSGet(_T("C"), asDblArray(xdPt3), asDblArray(xdPt4), retRb, ss);
if (rt != RTNORM)
{
AcGePoint3d setPosPt(xdPt3.x, xdPt3.y, ptz);
AcGePoint3d setAliPt = CGePointUtil::PolarPoint(setPosPt, CMathUtil::PI() * 0.5, hh * 0.5);
pAttr->setHorizontalMode(AcDb::kTextLeft);
pAttr->setVerticalMode(AcDb::kTextVertMid);
pAttr->setPosition(setPosPt);
pAttr->setAlignmentPoint(setAliPt);
acutRelRb(retRb);
acedSSFree(ss);
result = false;
break;
}
else
{
acutRelRb(retRb);
acedSSFree(ss);
result = true;
}
}
}
if (result)
{
// 设定向右移动限制
double yzLen = hh * 4;
double yLen = 0;
while (yLen < yzLen)
{
yLen = yLen + hh * 0.25;
xdPt5 = CGePointUtil::PolarPoint(xdPt3, 0.0, yLen);
xdPt6 = CGePointUtil::PolarPoint(xdPt4, 0.0, yLen);
retRb = acutBuildList(-4, _T("<NOT"), 2, _T("GC200"), -4, _T("NOT>"), RTNONE);
int rt = acedSSGet(_T("C"), asDblArray(xdPt5), asDblArray(xdPt6), retRb, ss);
if (rt != RTNORM)
{
AcGePoint3d setPosPt(xdPt5.x, xdPt5.y, ptz);
AcGePoint3d setAliPt = CGePointUtil::PolarPoint(setPosPt, CMathUtil::PI() * 0.5, hh * 0.5);
pAttr->setHorizontalMode(AcDb::kTextLeft);
pAttr->setVerticalMode(AcDb::kTextVertMid);
pAttr->setPosition(setPosPt);
pAttr->setAlignmentPoint(setAliPt);
acutRelRb(retRb);
acedSSFree(ss);
result = false;
break;
}
else
{
acutRelRb(retRb);
acedSSFree(ss);
result = true;
}
}
}
if (result)
{
// 设定向下移动限制
double yzLen = hh;
double yLen = 0;
while (yLen < yzLen)
{
yLen = yLen + hh * 0.25;
xdPt7 = CGePointUtil::PolarPoint(xdPt5, CMathUtil::PI() * 1.5, yLen);
xdPt8 = CGePointUtil::PolarPoint(xdPt6, CMathUtil::PI() * 1.5, yLen);
retRb = acutBuildList(-4, _T("<NOT"), 2, _T("GC200"), -4, _T("NOT>"), RTNONE);
int rt = acedSSGet(_T("C"), asDblArray(xdPt7), asDblArray(xdPt8), retRb, ss);
if (rt != RTNORM)
{
AcGePoint3d setPosPt(xdPt7.x, xdPt7.y, ptz);
AcGePoint3d setAliPt = CGePointUtil::PolarPoint(setPosPt, CMathUtil::PI() * 0.5, hh * 0.5);
pAttr->setHorizontalMode(AcDb::kTextLeft);
pAttr->setVerticalMode(AcDb::kTextVertMid);
pAttr->setPosition(setPosPt);
pAttr->setAlignmentPoint(setAliPt);
acutRelRb(retRb);
acedSSFree(ss);
result = false;
break;
}
else
{
acutRelRb(retRb);
acedSSFree(ss);
result = true;
}
}
if (result)
{
ptArray.append(pt3d);
}
}
pAttr->close();
delete pAttrIter;
pBlk->close();
pEnt->close();
}
}
acutRelRb(rb);
if (ptArray.length() > 0)
{
CLayerUtil::Add(_T("检查"), 1);
int i = 0;
for (i; i < ptArray.length(); i++)
{
AcGeVector3d vec(0, 0, 1);
AcDbCircle *pCircle = new AcDbCircle(ptArray, vec, 2.0);
pCircle->setLayer(_T("检查"));
CDwgDatabaseUtil::PostToModelSpace(pCircle);
}
acutPrintf(_T("\n高程点处理完毕,有: %d 个未处理。已画圆为标记请检查!"), i);
}
}
else
{
AfxMessageBox(_T("只限定CASS的合成高程点!"));
acutRelRb(rb);
}
CDwgDatabaseUtil::setVar(_T("osmode"), iosmode); // 还原捕捉状态值
acDocManager->unlockDocument(acDocManager->curDocument()); 老大又玩啥语言了 钟情ObjectARX的速度 图面检查怎么没有了?郁闷可否给一份!253406939@qq.com谢谢了!期待!!!!! 一级棒,测绘同仁的骄傲,能分享插件最好