//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(); }
符老师,pcDef对象能够获取到,但是通过
var pc = ParametricCellElement.Create(pcDef, setName, dgnModel);
这段代码获取到pc一直为null。
setName改成NULL,你当前文件下应该没有创建“standard”的set