//ElmentHandler eh;(参数化单元)
FindInstancesScopePtr scope = FindInstancesScope::CreateScope(eh, FindInstancesScopeOption(DgnECHostType::All)); ECQueryPtr query = ECQuery::CreateQuery(ECQUERY_PROCESS_SearchAllClasses); DgnECInstanceIterable iterable = Bentley::DgnPlatform::DgnECManager::GetManager().FindInstances(*scope, *query); for (DgnECInstanceIterable::const_iterator it = iterable.begin(); it != iterable.end(); ++it) { DgnECInstancePtr instance = *it; ECN::ECClassCR instanceClass = instance->GetClass(); WString classDisplayName = instanceClass.GetDisplayLabel();
ECPropertyIterable properties = instanceClass.GetProperties(); for (ECPropertyIterable::const_iterator it = properties.begin(); it != properties.end(); ++it) { ECValue v; ECPropertyCP pProp = (*it); if (pProp->GetName().find(L"ParameterValuesContainer")) continue;
ECValue v1;
WCharCP propertyAccessString = pProp->GetName().c_str(); ECObjectsStatus status = instance->GetValue(v1, propertyAccessString, 0); if (ECOBJECTS_STATUS_Success != status) continue;
}
现在我能获取ECValue v1,调试看到其如下形式:
看了下帮助文档没发现读取struct里面的值的函数,希望得到大家的帮助!
您是想在复制参数化单元时修改参数的值吗?这一块底层相当复杂,我给你一个样例供你参考:
private static DgnModel LocateCellModel(string name) { var opts = CellLibraryOptions.Include3d | CellLibraryOptions.IncludeAllLibraries | CellLibraryOptions.IncludeParametric; var libs = new CellLibraryCollection(opts); DgnModel cellModel = null; foreach (var lib in libs) { MessageCenter.Instance.ShowInfoMessage(lib.Name, lib.Name, false); if (name.Equals(lib.Name)) { StatusInt status; cellModel = lib.File.LoadRootModelById(out status, lib.File.FindModelIdByName(lib.Name), true, false, true); break; } } return cellModel; } public static void CreateParametricCell(string pcName) { const string setName = "Standard"; var dgnFile = Session.Instance.GetActiveDgnFile(); var dgnModel = Session.Instance.GetActiveDgnModel(); var pcDef = ParametricCellDefinitionElement.FindByName(pcName, dgnFile); if (null == pcDef) //Not find cell def in active design file { var cellModel = LocateCellModel(pcName); if (null == cellModel) { MessageCenter.Instance.ShowErrorMessage("Not found cell", null, true); return; } var hdlr = DgnComponentDefinitionHandler.GetForModel(cellModel); var status = hdlr.DefinitionModelHandler.CreateCellDefinition(dgnFile); if (ParameterStatus.Success == status) pcDef = ParametricCellDefinitionElement.FindByName(pcName, dgnFile); else { MessageCenter.Instance.ShowErrorMessage("Error Creating cellDef", null, true); return; } } //IECStructArrayValue, IECArrayValue, IECStructValue, IECPropertyValue var pc = ParametricCellElement.Create(pcDef, setName, dgnModel); IDgnECInstance inst = pc.Parameters as IDgnECInstance; IECArrayValue arr = inst.GetPropertyValue("ParameterValuesContainer") as IECArrayValue; IECStructValue structVal = arr[1] as IECStructValue; // .Adhoc_Name = _LOCAL_Cabinet_W structVal.SetValue("Adhoc_Value", 2.0); inst.ScheduleChanges(pc); DTransform3d trans = DTransform3d.Identity; trans.Translation = new DVector3d(1000, 2000, 3000); //UOR unit TransformInfo transInfo = new TransformInfo(trans); pc.ApplyTransform(transInfo); pc.AddToModel(); }
老师,您上面的 inst.ScheduleChanges(pc); 应该是刷新保存修改吧 。在c++里怎么实现啊。我下面问了郑岗老师还没回我。 我用他的方法能修改并打印出来参数值,但是并没有应用到我当前模型上。
DgnECInstance下的WriteChanges函数。
我用了好像还是改不了。
void changeParametricCell(EditElementHandleCR eeh) { FindInstancesScopePtr scope = FindInstancesScope::CreateScope(eeh, FindInstancesScopeOption(DgnECHostType::All)); ECQueryPtr query = ECQuery::CreateQuery(ECQUERY_PROCESS_SearchAllClasses); DgnECInstanceIterable iterable = Bentley::DgnPlatform::DgnECManager::GetManager().FindInstances(*scope, *query); DgnECInstancePtr instance = *(++(iterable.begin())); WString filename; ECN::ECClassCR instanceClass = instance->GetClass(); ECPropertyIterable properties = instanceClass.GetProperties(); for (ECPropertyIterable::const_iterator it0 = properties.begin(); it0 != properties.end(); ++it0) { ECValue v; ECPropertyCP pProp = (*it0); if (pProp->GetName().Equals(L"ParameterValuesContainer")) { if (pProp->GetIsArray()) { ArrayECPropertyCP aep = pProp->GetAsArrayProperty(); ECN::ECClassCP _instanceClass = aep->GetStructElementType(); ECPropertyIterable _properties = _instanceClass->GetProperties(false); //获取数组个数 instance->GetValue(v, pProp->GetName().data()); ArrayInfo ai = v.GetArrayInfo(); int count = ai.GetCount(); for (int index = 0; index < count; index++) { instance->GetValue(v, pProp->GetName().data(), index); IECInstancePtr _intance = v.GetStruct(); for (ECPropertyIterable::const_iterator it1 = _properties.begin(); it1 != _properties.end(); ++it1) { if ((*it1)->GetName().Equals(L"Adhoc_Label") || (*it1)->GetName().Equals(L"Adhoc_Value") || (*it1)->GetName().Equals(L"Adhoc_Type")) { ECValue _v; _intance->GetValue(_v, (*it1)->GetName().data()); if (wcscmp(_v.GetString(), L"网格长") == 0) { ECValue value1(L"1.23"); _intance->SetValue(L"Adhoc_Value", value1); // _intance->ChangeValue(L"Adhoc_Value", value1); break; } } } } } } } filename.Sprintf(L"D:\\1.xml"); instance->WriteToXmlFile(filename.data(), true, true); instance->WriteChanges(); } void changeParametricCell0(EditElementHandleCR eeh) { FindInstancesScopePtr scope = FindInstancesScope::CreateScope(eeh, FindInstancesScopeOption(DgnECHostType::All)); ECQueryPtr query = ECQuery::CreateQuery(ECQUERY_PROCESS_SearchAllClasses); DgnECInstanceIterable iterable = Bentley::DgnPlatform::DgnECManager::GetManager().FindInstances(*scope, *query); DgnECInstancePtr instance = *(++(iterable.begin())); WString filename; ECN::ECClassCR instanceClass = instance->GetClass(); ECPropertyIterable properties = instanceClass.GetProperties(); filename.Sprintf(L"D:\\2.xml"); instance->WriteToXmlFile(filename.data(), true, true); } ParametricCellHandler& pcHandler = ParametricCellHandler::GetInstance(); EditElementHandle eeh; if (ParameterStatus::Success != pcHandler.CreateCellElement(eeh, *pcInfo)) return; changeParametricCell(eeh); changeParametricCell0(eeh); eeh.AddToModel();
我用instance->ScheduleWriteChanges(eeh);可以保存在模型上了,但是好像参数类型不对,我写进去的Adhoc_Value的类型是字符串,但是它实际的类型是double类型的,我写进去好像只是单纯的显示文本变了,里面的double值没变,模型的参数值虽然是1m,但是实际还是4m。而且修改后的那个参数我在CE上直接手动修改并没有应用到模型上,好像失效了。
你先用Mstn自带的参数化单元试试(C:\ProgramData\Bentley\MicroStation CONNECT Edition\Configuration\WorkSpaces\Example\WorkSets\MetroStation\DGN\Parametric Models\Double Door Cabinet.dgn),修改参数成功了再用你自己的 参数化单元。
好了 谢谢老师,我刚刚换了个参数化单元好了,是我参数化单元的问题
您好,我也遇到了 类似的问题,就是 有时候可以修改参数值,有时候 修改后 属性值改了 但是 元素的实际值测量后没有修改成功,有的时候 就根本修改不了了。
所以想咨询一下,您那个修改不了 是什么原因?另外您修改成功后的代码能 发上来 学习一下嘛?
Bentley 二次开发小白一枚
我的是自己建的参数化单元,设置的参数和约束太多了,导致修改参数不成功,你用上面郭老师说的mstn自带的参数化单元试下,或者你建个最简单的参数化单元,代码我就是用上面郑老师提供的方法修改的,上面我也贴了关键代码。主要就是看你参数化单元是不是有问题。
instance->ScheduleWriteChanges(eeh); 有用到这个嘛?
嗯 要的