• ObjectARX通过选定的实体获取所有组名示例


    效果

    方式一

    通过实体所在对象的永久反应器获取组对象

    		ads_name ent;
    		ads_point pt;
    		if (RTNORM != acedEntSel(_T("
    选择对象: "),ent,pt))
    		{
    			return;
    		}
    		AcDbObjectId objId;
    		acdbGetObjectId(objId,ent);
    		AcDbEntityPointer pEnt(objId,AcDb::kForRead);
    		Acad::ErrorStatus es=pEnt.openStatus();
    		if (Acad::eOk != es)
    		{
    			acutPrintf(_T("
    打开对象失败,错误码=%s"),acadErrorStatusText(es));
    			return;
    		}
    		const AcDbVoidPtrArray *pReactors=pEnt->reactors();
    		if (pReactors==NULL || pReactors->length()<1)
    		{
    			acutPrintf(_T("
    该对象没有组!"));
    			return;
    		}
    		CStringArray strGroupNames;
    		for (int i=0;i<pReactors->length();i++)
    		{
    			void* pSomething = pReactors->at(i);
    			if (pSomething==NULL) continue;
    			if (!acdbIsPersistentReactor(pSomething)) continue;
    			AcDbObjectId persReactorId=acdbPersistentReactorObjectId(pSomething);
    			AcDbObjectPointer<AcDbGroup> pGroup(persReactorId,AcDb::kForRead);
    			if (Acad::eOk != es) continue;			
    			strGroupNames.Add(pGroup->name());
    		}
    		int nCount=strGroupNames.GetCount();
    		if (nCount<1)
    		{
    			acutPrintf(_T("
    该对象没有组!"));
    			return;
    		}
    		acutPrintf(_T("
    该对象拥有 %d 个组"),nCount);
    		for (int i=0;i<nCount;i++)
    		{
    			acutPrintf(_T("
    第 %d 个组名为 %s ."),i+1,strGroupNames.GetAt(i));
    		}
    

    方式二

    通过遍历组字典判断组是否包含实体对象来获取组对象

    		ads_name ent;
    		ads_point pt;
    		if (RTNORM != acedEntSel(_T("
    选择对象: "),ent,pt))
    		{
    			return;
    		}
    		AcDbObjectId objId;
    		acdbGetObjectId(objId,ent);
    		AcDbEntityPointer pEnt(objId,AcDb::kForRead);
    		Acad::ErrorStatus es=pEnt.openStatus();
    		if (Acad::eOk != es)
    		{
    			acutPrintf(_T("
    打开对象失败,错误码=%s"),acadErrorStatusText(es));
    			return;
    		}
    		AcDbObjectId groupDicId=acdbHostApplicationServices()->workingDatabase()->groupDictionaryId();
    		AcDbObjectPointer<AcDbDictionary> pGroupDic(groupDicId,AcDb::kForRead);
    		es=pGroupDic.openStatus();
    		if (Acad::eOk != es)
    		{
    			acutPrintf(_T("
    打开组字典失败,错误码=%s"),acadErrorStatusText(es));
    			return;
    		}
    		CStringArray strGroupNames;
    		AcDbDictionaryIterator *pIter= pGroupDic->newIterator();
    		for (;!pIter->done();pIter->next())
    		{
    			AcDbObjectId groupId= pIter->objectId();
    			AcDbObjectPointer<AcDbGroup> pGroup(groupId,AcDb::kForRead);
    			es = pGroup.openStatus();
    			if (Acad::eOk != es)
    			{
    				acutPrintf(_T("
    打开组失败,错误码=%s"),acadErrorStatusText(es));
    				continue;
    			}
    			if (pGroup->has(pEnt))
    			{
    				strGroupNames.Add(pGroup->name());
    			}			
    		}
    		if (pIter!=NULL)
    		{
    			delete pIter;
    		}
    		int nCount=strGroupNames.GetCount();
    		if (nCount<1)
    		{
    			acutPrintf(_T("
    该对象没有组!"));
    			return;
    		}
    		acutPrintf(_T("
    该对象拥有 %d 个组"),nCount);
    		for (int i=0;i<nCount;i++)
    		{
    			acutPrintf(_T("
    第 %d 个组名为 %s ."),i+1,strGroupNames.GetAt(i));
    		}
    
  • 相关阅读:
    Xftp6 和 Xshell 6 下载与安装使用
    Oracle 11 安装教程(桌面类)
    Oracle 11 安装 提示环境不满足最低要求解决方案
    FICO年终完全手册
    SAP月结操作讲解
    ABAP-FI常用BAPI
    FB01与F-02的区别(转载)
    SAP应用创新-维护控制表、视图统一路径
    FI 业务
    SAP 财务模块 FI-TV 差旅管理
  • 原文地址:https://www.cnblogs.com/edata/p/14968757.html
Copyright © 2020-2023  润新知