【OPMCE C#】获取选中弯头或管道的进出口坐标

请问选中弯头或管道后,如何获取其进出口坐标呢?能否将获取到的Element转换为PipeComponent?

  • 获取进出口坐标,建议你从port入手,目前至少有两种办法

    1.从IECInstance入手:

    通过查看element的属性

    代码我就不写了,顺着这个顺序找到 Child Element,然后获取 Properties ,通过 IECClass 定位到具体的 IECInstance ,然后就可以获取到了。

    但是注意,这里的 location 获取的是局部坐标,如果需要全局坐标,需要进行坐标转换,矩阵请从Element上获取

    2.通过port对象获取

    Port 定义在 Bentley.Building.Mechanical.Components 中,在OPM提供的 Bentley.OpenPlant.Modeler.Api 程序集中提供了大量关于 Port 的方法,例如

    Bentley.OpenPlant.Modeler.Api.BMECApi.Instance.GetConnectedPortInstance(portInstance)// port instance --> port instance

    Bentley.OpenPlant.Modeler.Api.BMECApi.Instance.GetPortsForComponent(component)//component --> port ecinstance list

    Bentley.OpenPlant.Modeler.Api.BMECApi.Instance.GetPortOwnerComponent(portInstance)//port ecinstance --> component

    Bentley.OpenPlant.Modeler.Api.BMECApi.Instance.GetPorts(component)//component --> port

    该程序集下还有大量其他有用的方法,有兴趣可以自行研究。

    获取到Port对象后,可以直接从属性中获取到location

    Answer Verified By: JiHong Duan