老师好:
/*-------------------------------------------------------- | getAllInstances +-------------------------------------------------------*/ WCharCP getCategoryName(ECPropertyP ecProp) { IECInstancePtr categoryInstance = ecProp->GetCustomAttribute(WString(L"Category")); if (categoryInstance.IsValid()) { ECValue ecVal1, ecVal2; categoryInstance->GetValue(ecVal1, L"Standard"); categoryInstance->GetValue(ecVal2, L"DisplayLabel"); WString result =ecVal1.ToString() + WString(L" | ") + ecVal2.ToString(); return result.GetWCharCP(); } else return L"No Category"; } void getAllInstances(WCharCP unparsed) { ElementHandle eh(2013L, ACTIVEMODEL); DgnECManagerR ecMgr = DgnECManager::GetManager(); FindInstancesScopePtr scope = FindInstancesScope::CreateScope(eh, FindInstancesScopeOption(DgnECHostType::Element)); ECQueryPtr ecQuery = ECQuery::CreateQuery (ECQUERY_PROCESS_SearchAllClasses); //ECQUERY_PROCESS_SearchAllExtrinsic will only search ECXAttr ecQuery->SetSelectProperties(true); for (DgnECInstancePtr instance : ecMgr.FindInstances(*scope, *ecQuery)) { DgnElementECInstanceP elemInst = instance->GetAsElementInstance(); WPrintfString outStr(L"--------- className = %s, instanceId = %s ---------------", elemInst->GetClass().GetName().GetWCharCP(), elemInst->GetInstanceId().GetWCharCP()); mdlDialog_dmsgsPrint(outStr); for (ECPropertyP ecProp : elemInst->GetClass().GetProperties()) { WString valStr; ECValue ecVal; elemInst->GetValue(ecVal, ecProp->GetName().GetWCharCP()); IDgnECTypeAdapterR typeAdapter = IDgnECTypeAdapter::GetForProperty(*ecProp); IDgnECTypeAdapterContextPtr typeContext = IDgnECTypeAdapterContext::Create(*ecProp, *elemInst, ecProp->GetName().GetWCharCP()); typeAdapter.ConvertToString(valStr, ecVal, *typeContext); WPrintfString outStr2(L"\t%s[%s] = %s (categoryName=%s)", ecProp->GetDisplayLabel().GetWCharCP(), ecProp->GetTypeName().GetWCharCP(), valStr.GetWCharCP(), getCategoryName(ecProp)); mdlDialog_dmsgsPrint(outStr2); } } }
Answer Verified By: 平凡人生
DisplayHandler* pdh = eeh.GetDisplayHandler(); RotMatrix rm; Transform tr; dhT.GetOrientation(eeh, rm); dhT.GetBasisTransform(eeh, tr);
这个方法 是否可行?有什么区别吗?
Bentley 二次开发小白一枚
不建议调用单个函数去获得元素属性,因为这么多属性你得一个个去找对应的函数。而我们提供给您的是通过EC编程一次性获得元素所有的属性的。
老师你好,我想问一下还有其他的获取属性的方法吗?因为我测试发现获取属性所耗费的时间占整个程序的一大半,所以想看看有没有更快的方法。
如果您仅想获得某个或某几个特定的属性,可以考虑调用特定的函数。如果是所有属性都要获取的话,还是需要沿用现在的这个EC的方法。
好的,谢谢