PS编程模型中有PsMiscTools类,其下的GetProStructuresIdFromActiveModelCADId可以将MicroStation的一个元素ID转换为PS中对应的物体Id。如下VB.NET代码演示了这个功能:
Shared Sub example_native_cad_select() Dim oEnu As ElementEnumerator = AddInMain.ComApp.ActiveModelReference.GetSelectedElements() Dim id, psid As Long Do While oEnu.MoveNext Dim oElement As Element = oEnu.Current id = oElement.ID psid = PsMiscTools.GetProStructuresIdFromActiveModelCADId(id) Dim prop As New PsObjectProperties prop.readFrom(psid) If prop.ObjectType = ObjectType.kPlate Then Dim Trans As New PsTransaction Dim Plate As PsPlate = Nothing Try Trans.GetObject(psid, PsOpenMode.kForWrite, Plate) MsgBox("Name from Entity=" + Plate.Name) Catch ex As System.Exception MsgBox(ex.Message) Finally Trans.Close() Plate = Nothing End Try Else MsgBox("Name from Props=" + prop.Name) End If Loop End Sub
请注意:该方法只能适应于对当前模型中的ElementID的转换。