符老师 参数话单元获得itemtype 变量 以及获得 变化值
求指导
请参考如下代码,其中的ParameterSet就是变化(Variation)值。
public static void PCParams(string unparsed) { string pcName = (unparsed == "") ? "Double Door Cabinet" : unparsed; var dgnFile = Session.Instance.GetActiveDgnFile(); var pcDef = ParametricCellDefinitionElement.FindByName(pcName, dgnFile); if (null == pcDef) //Not find cell def in active design file { var cellModel = CreateElements.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; } } string msg = "[" + pcName + "] includes below Variations:\n"; foreach (ParameterSet ps in pcDef.ParameterSets) { msg += ps.Name + "\n"; } MessageCenter.Instance.ShowInfoMessage(msg, null, true); msg = "[" + pcName + "] includes below ParameterDefinitions:\n"; foreach (ParameterDefinition pd in pcDef.ParameterDefinitions) { if (!pd.IsHidden) msg += "AccessString=" + pd.AccessString + ", DispalyLabel=" + pd.DisplayLabel + "\n"; } MessageCenter.Instance.ShowInfoMessage(msg, null, true); msg = "[" + pcName + "] includes below Parameters:\n"; foreach (var p in pcDef.Parameters) { msg += "AccessString=" + p.AccessString + ", Value=" + p.StringValue + "\n"; } MessageCenter.Instance.ShowInfoMessage(msg, null, true); }
Answer Verified By: Andy
LocateCellModel函数如下:
public 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; }
符老师 能得到单位么获得值的时候 我没得到单位 Parameters dump 也没看到单位
这个帖子中的C++代码含有如下三行关键代码,能获得属性的值和单位,就和我们从Property对话框中看到的一模一样。
https://communities.bentley.com/communities/other_communities/chinafirst/f/microstation-projectwise/195388/msce-c
IDgnECTypeAdapterR typeAdapter = IDgnECTypeAdapter::GetForProperty(*ecProp); IDgnECTypeAdapterContextPtr typeContext = IDgnECTypeAdapterContext::Create(*ecProp, *elemInst, ecProp->GetName().GetWCharCP()); typeAdapter.ConvertToString(valStr, ecVal, *typeContext);
C# 中没有找到对应的方法。
符老师 找了好久没找到 C# IDgnECInstance怎么转C++ DgnECInstancePtr 找到一个Bentley.DgnPlatformNET.DgnEC.DgnECManager.Manager.ConvertManagedInstanceToNative 没转成 intptr
求指教