<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://communities.bentley.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>如何将MicroStation中的元素转换为PS中的物体？</title><link>https://communities.bentley.com/communities/other_communities/chinafirst/w/chinawiki/38229/microstation-ps</link><description /><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>如何将MicroStation中的元素转换为PS中的物体？</title><link>https://communities.bentley.com/communities/other_communities/chinafirst/w/chinawiki/38229/microstation-ps</link><pubDate>Mon, 16 Apr 2018 07:04:31 GMT</pubDate><guid isPermaLink="false">6dad98f5-dbc9-4c4d-a9ba-e9da8dc6aa8e:66898818-4dad-4ce7-ab7c-78b1e76aba55</guid><dc:creator>Yongan.Fu</dc:creator><comments>https://communities.bentley.com/communities/other_communities/chinafirst/w/chinawiki/38229/microstation-ps#comments</comments><description>Current Revision posted to 技术资料库 by Yongan.Fu on 4/16/2018 7:04:31 AM&lt;br /&gt;
&lt;p&gt;PS编程模型中有PsMiscTools类，其下的GetProStructuresIdFromActiveModelCADId可以将MicroStation的一个元素ID转换为PS中对应的物体Id。如下VB.NET代码演示了这个功能：&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;    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(&amp;quot;Name from Entity=&amp;quot; + Plate.Name)
                Catch ex As System.Exception
                    MsgBox(ex.Message)
                Finally
                    Trans.Close()
                    Plate = Nothing
                End Try

            Else
                MsgBox(&amp;quot;Name from Props=&amp;quot; + prop.Name)
            End If
        Loop
    End Sub
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;请注意：该方法只能适应于对当前模型中的ElementID的转换。&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;
</description></item></channel></rss>