怎么亮显块内单个实体
本帖最后由 czx1234567 于 2016-6-1 13:31 编辑请教,怎么亮显块参照内的单个实体(不是子实体),如文本,线段等。
Objectarx帮助文件里有亮显嵌套块参照子实体的例子,但那个似乎不能用于文本等简单实体的亮显。
下面的代码能获得块内实体的指针,不知道为什么不能亮显。
ads_name ename;
ads_matrix adsmat;
struct resbuf *insStack;
acedNEntSelP(NULL, ename, pickpoint, TRUE, adsmat, &insStack);
AcDbObjectId objectId;
acdbGetObjectId(objectId, ename);
AcDbEntity *pEnt = NULL;
acdbOpenAcDbEntity(pEnt, objectId, AcDb::kForWrite);
pEnt ->highlight();
大佬C#的代码有吗,或者用法,我研究半天搞不懂 下载试试,谢谢源码! 好东西,收藏一下 似乎是个难题。搜了几天没搜到答案。但应该是可以实现的。 问题终于得到解决。原来是我没仔细看懂Objectarx帮助文件中的实例。很简单几行代码实现块内实体亮显功能,关键是弄懂AcDbFullSubentPath类的构造。
void HighlightEntityInBlock(ads_point pickpoint, bool bHighlight)
{
ads_name ename;
ads_matrix adsmat;
struct resbuf *insStack;
acedNEntSelP(NULL, ename, pickpoint, TRUE, adsmat, &insStack);
AcDbObjectId selId;
acdbGetObjectId(selId, ename);
ads_name sset;
acedSSGet(NULL, pickpoint, NULL, NULL, sset);
acedSSName(sset, 0, ename);
AcDbObjectId blRefId;
acdbGetObjectId(blRefId, ename);
AcDbEntity *pEnt = NULL;
acdbOpenAcDbEntity(pEnt, blRefId, AcDb::kForRead);
AcDbBlockReference *pBlock = AcDbBlockReference::cast(pEnt);
AcDbFullSubentPath subPath;
subPath.objectIds().append(blRefId);
subPath.objectIds().append(selId);
if (bHighlight)
pBlock->highlight(subPath);
else
pBlock->unhighlight(subPath);
pBlock->close();
}
上面的代码只能显示单层块参照实体。对于多层嵌套块参照可以用下面的代码。
void CAddToDwg::HighlightEntityInBlock(ads_point pickpoint, bool bHighlight)
{
ads_name ename;
ads_matrix adsmat;
struct resbuf *insStack;
acedNEntSelP(NULL, ename, pickpoint, TRUE, adsmat, &insStack);
AcDbObjectId selId;
acdbGetObjectId(selId, ename);
ads_name sset;
acedSSGet(NULL, pickpoint, NULL, NULL, sset);
acedSSName(sset, 0, ename);
AcDbObjectId blRefId;
acdbGetObjectId(blRefId, ename);
int count = 0;
struct resbuf *rbIter = insStack;
AcDbObjectId *idArray = new AcDbObjectId;
AcDbObjectId objectId;
while (rbIter != NULL && count <100)
{
ename = rbIter->resval.rlname;
ename = rbIter->resval.rlname;
acdbGetObjectId(objectId, ename);
idArray = objectId;
rbIter = rbIter->rbnext;
count++;
}
acutRelRb(insStack);
AcDbFullSubentPath subPath;
for (int i = count; i > 0; i--)
{
subPath.objectIds().append(idArray);
}
AcDbEntity *pEntSel = NULL;
acdbOpenAcDbEntity(pEntSel, selId, AcDb::kForRead);
if (pEntSel ->isKindOf(AcDbAttribute::desc()))
subPath.objectIds().append(pEntSel ->ownerId());
pEntSel ->close();
subPath.objectIds().append(selId);
AcDbEntity *pEnt = NULL;
acdbOpenAcDbEntity(pEnt, blRefId, AcDb::kForRead);
AcDbBlockReference *pBlock = AcDbBlockReference::cast(pEnt);
if (bHighlight)
pBlock->highlight(subPath);
else
pBlock->unhighlight(subPath);
pBlock->close();
}
本帖最后由 czx1234567 于 2016-6-6 12:38 编辑
还可以简化
void CAddToDwg::HighlightEntityInBlock(ads_point pickpoint, bool bHighlight)
{
ads_name ename;
ads_matrix adsmat;
struct resbuf *insStack;
acedNEntSelP(NULL, ename, pickpoint, TRUE, adsmat, &insStack);
AcDbObjectId selId;
acdbGetObjectId(selId, ename);
//ads_name sset;
//acedSSGet(NULL, pickpoint, NULL, NULL, sset);
//acedSSName(sset, 0, ename);
//AcDbObjectId blRefId;
//acdbGetObjectId(blRefId, ename);
int count = 0;
struct resbuf *rbIter = insStack;
AcDbObjectId *idArray = new AcDbObjectId;
AcDbObjectId objectId;
while (rbIter != NULL && count <100)
{
ename = rbIter->resval.rlname;
ename = rbIter->resval.rlname;
acdbGetObjectId(objectId, ename);
idArray = objectId;
rbIter = rbIter->rbnext;
count++;
}
acutRelRb(insStack);
AcDbFullSubentPath subPath;
for (int i = count; i > 0; i--)
{
subPath.objectIds().append(idArray);
}
AcDbEntity *pEntSel = NULL;
acdbOpenAcDbEntity(pEntSel, selId, AcDb::kForRead);
if (pEntSel ->isKindOf(AcDbAttribute::desc()))
subPath.objectIds().append(pEntSel ->ownerId());
pEntSel ->close();
subPath.objectIds().append(selId);
AcDbEntity *pEnt = NULL;
acdbOpenAcDbEntity(pEnt, subPath.objectIds().first(), AcDb::kForRead);
//AcDbBlockReference *pBlock = AcDbBlockReference::cast(pEnt);
if (bHighlight)
pEnt->highlight(subPath);
else
pEnt->unhighlight(subPath);
pEnt->close();
} 多谢,lz知道如何写自定义实体的选择子实体,类似于 多段线中 夹角标注时可以选择多段线的2个边进行操作 czx1234567 发表于 2016-6-3 15:26 static/image/common/back.gif
上面的代码只能显示单层块参照实体。对于多层嵌套块参照可以用下面的代码。
void CAddToDwg::HighlightE ...
楼主,我也被类似的问题困扰了好一阵了,是怎样重载AcDbEntity的virtual Acad::ErrorStatus subHighlight,不知道你清不清楚 谢谢楼主分享,好经验
页:
[1]
2