ObjectARX创建组简单实例之setSelectable
效果展示
创建组函数代码
static Acad::ErrorStatus CreateGroup(const AcDbObjectIdArray objIds,AcDbObjectId &outGroupId,const CString sGroupName=_T("*"),AcDbDatabase *pDb=curDoc()->database())
{
if (objIds.length()<1)
{
return Acad::eNullObjectId;
}
if (pDb == NULL)
{
return Acad::eNoDatabase;
}
AcDbDictionary *pGroupDic=NULL;
Acad::ErrorStatus es= pDb->getGroupDictionary(pGroupDic,AcDb::kForRead);
if (Acad::eOk != es) return es;
AcDbDictionaryPointer pGroupDicPtr;
es = pGroupDicPtr.acquire(pGroupDic);
if (Acad::eOk != es)
{
pGroupDic->close();
return es;
}
if (sGroupName != _T("*"))
{
es= pGroupDicPtr->getAt(sGroupName,outGroupId);
if (Acad::eOk == es)
{
return Acad::eDuplicateKey;
}
}
es= pGroupDicPtr->upgradeOpen();
if (Acad::eOk != es) return es;
AcDbObjectPointer<AcDbGroup> pGroup;
es=pGroup.create();
if (Acad::eOk != es) return es;
es= pGroup->append(objIds);
if (Acad::eOk != es) return es;
//设置 可以选择,如果为false,则会没有组选择效果
es = pGroup->setSelectable(true);
return pGroupDicPtr->setAt(sGroupName,pGroup,outGroupId);
}
调用示例
ads_name ss;
if (RTNORM != acedSSGet(NULL,NULL,NULL,NULL,ss))
{
return;
}
AcDbObjectIdArray objIds;
Adesk::Int32 nLength=0;
acedSSLength(ss,&nLength);
for (int i=0;i<nLength;i++)
{
ads_name ent;
acedSSName(ss,i,ent);
AcDbObjectId objId;
acdbGetObjectId(objId,ent);
if (!objId.isNull())
{
objIds.append(objId);
}
}
AcDbObjectId groupId;
Acad::ErrorStatus es = CreateGroup(objIds,groupId,_T("AAAA"));
if (Acad::eOk != es)
{
acutPrintf(_T("\n创建失败,错误码=%s"),acadErrorStatusText(es));
}
else
{
acutPrintf(_T("\n创建成功"));
}