,我的代码片段
// 获得用户选择的路线 Bentley.CifNET.GeometryModel.RoadwayDesigner.Corridor rdCorridor = OrdObjectSpaceUtil.Active.GetObject<Bentley.CifNET.GeometryModel.RoadwayDesigner.Corridor>(element); Console.WriteLine(rdCorridor.Name); if (!(element.ElementType == (MSElementType) 106)) { MsNotificationUtil.OutputInfo("所选元素不是廊道对象"); return; } // ConsensusConnection m_con = new ConsensusConnection(Bentley.MstnPlatformNET.Session.Instance.GetActiveDgnModelRef()); Corridor corridor = (element.ParentElement == null) ? Corridor.CreateFromElement(m_con, element) : Corridor.CreateFromElement(m_con, element.ParentElement); if (corridor == null) { MsNotificationUtil.OutputInfo("所选元素不是廊道对象"); return; } try { Alignment corridorAlignment = corridor.CorridorAlignment; // 此处抛出AccessViolationException崩溃 } catch (AccessViolationException ex) { Trace.WriteLine(ex); }
提前谢过。
搜索
复制
请参考下面代码:
static void TestCorridor() { DgnModel activeModel = Session.Instance.GetActiveDgnModel(); CifNET.SDK.ConsensusConnection sdkCon = new CifNET.SDK.ConsensusConnection(activeModel); if ( sdkCon == null ) { MessageCenter.Instance.ShowInfoMessage("Can't get a connection", null, true); return; } foreach ( Bentley.CifNET.GeometryModel.SDK.GeometricModel gm in sdkCon.GetAllGeometricModels() ) { foreach ( Corridor corr in gm.Corridors ) { if ( corr != null ) { Alignment corridorAlignment = corr.CorridorAlignment; } } } sdkCon.Close(); }
谢谢回复,不过猜测您可能没用我发的用例测试。我用了您给的代码测试了下,结果依然。不过为我们提供了一种新的思路,相当于遍历枚举。
我就是用您提供的用例测试的,没有报异常,建议把china版本升级最新版再试试。
Answer Verified By: 晓强 首
不仅要升级ORD for China版本,还要升级CIMPlatformSDK的版本,因为这个SDK会向for China软件中更新某些DLL文件。
抱歉,我忘记了报我的使用环境了,OpenRailDesignerUpdate7