Loading... <!-- wp:paragraph {"fontSize":"normal"} --> <p class="has-normal-font-size">S3D中Codelist类型的属性无法直接获取到他们的长短描述,我们可以将这个过程封装成标准的提取方法,方便使用。</p> <!-- /wp:paragraph --> <!-- wp:paragraph {"fontSize":"normal"} --> <p class="has-normal-font-size">获取短描述,我们是要先获取到Codelist属性,然后要知道这个Codelist在后台数据库中的表名称和表空间类型(这两项可以在 Metadata Browser 中查询),一起传递到方法内,即可取到短描述。</p> <!-- /wp:paragraph --> <!-- wp:code --> <pre class="wp-block-code"><code>Public Function GetCodelistShortDesc(ByVal oPropCodeList As PropertyValueCodelist, ByVal sCodeListName As String, ByVal sCodeListSpace As String) As String Dim oMetaMgr As MetadataManager = MiddleServiceProvider.SiteMgr.ActiveSite.ActivePlant.PlantModel.MetadataMgr Dim oCodelistInfo As CodelistInformation Dim oCodelistItem As CodelistItem GetCodelistShortDesc = "" Try oCodelistInfo = oMetaMgr.GetCodelistInfo(sCodeListName, sCodeListSpace) oCodelistItem = oCodelistInfo.GetCodelistItem(oPropCodeList.PropValue) GetCodelistShortDesc = oCodelistItem.Name Catch ex As Exception MsgBox("GetCodelistShortDesc函数异常: " & ex.Message) End Try End Function</code></pre> <!-- /wp:code --> <!-- wp:paragraph {"fontSize":"normal"} --> <p class="has-normal-font-size">获取长描述比较简单,我们就代替原有的GetProperty方法,直接传递对象、接口,属性进来,就能获取到长描述了。当然,获取短描述其实也可以参考类似方法,但要传递的参数就多了,看你们自己喜欢。</p> <!-- /wp:paragraph --> <!-- wp:code --> <pre class="wp-block-code"><code>Public Function GetCodelistLongDesc(ByVal oBO As BusinessObject, ByVal sInterfaceName As String, ByVal sAttributeName As String) As String Dim sDesc As String = "" Dim oPropCodelist As PropertyValueCodelist Try oPropCodelist = oBO.GetPropertyValue(sInterfaceName, sAttributeName) sDesc = oPropCodelist.PropertyInfo.CodeListInfo.GetCodelistItem(oPropCodelist.PropValue).DisplayName Catch ex As Exception End Try Return sDesc End Function</code></pre> <!-- /wp:code --> <!-- wp:paragraph {"textColor":"vivid-red","fontSize":"normal"} --> <p class="has-text-color has-normal-font-size has-vivid-red-color"><strong>后记:某些直接通过封装好的方法获取的Codelist属性可以直接后缀加.ToString,直接得到它的短描述了。但是并不是普适的方法,上述获取方法是比较严谨的途径。</strong></p> <!-- /wp:paragraph --> 最后修改:2025 年 03 月 13 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 如果觉得我的文章对你有用,请随意赞赏