Sparx Enterprise Architect从otDiagram VB脚本代码中获取Tagged'值

时间:2014-10-28 14:12:50

标签: vbscript enterprise-architect

我有一个UML图,所有组件都有标记值。我想用元素名称检索标记值。像这样的东西来获取标记值,我有代码但不知道如何为图表启动它。

function TVGetElementTaggedValue( theElement, taggedValueName, defaultValue )
    TVGetElementTaggedValue = defaultValue

    if not theElement is nothing and Len(taggedValueName) > 0 then
        dim taggedValue as EA.TaggedValue
        set taggedValue = theElement.TaggedValues.GetByName( taggedValueName )

        if not taggedValue is nothing then
            TVGetElementTaggedValue = taggedValue.Value
        end if
    end if

end function

2 个答案:

答案 0 :(得分:1)

图表上没有标记值。

答案 1 :(得分:1)

最后这是我拥有的解决方案,最终有效:

  1. 首先选择如下类型:Repository.GetTreeSelectedItemType() = otDiagram
  2. 调用一个函数并保留一个变量来存储数据,如下所示: Roles = TVGetElementTaggedValue(element, "Roles", "", "")
  3. 这是功能:

  4. Function TVGetElementTaggedValue( theElement, taggedValueName, defaultValueMissing, defaultValueEmpty )
    
        if not theElement is nothing and Len(taggedValueName) > 0 then      
            dim taggedValue as EA.TaggedValue
            set taggedValue = theElement.TaggedValues.GetByName( taggedValueName )
    
            if taggedValue is nothing then
                TVGetElementTaggedValue = defaultValueMissing
    ' Dump warning          
    'Session.Output(theElement.Name & " " & taggedValueName & " TAG Missing")           
            else
                if taggedValue.Value = "" then
                    TVGetElementTaggedValue = defaultValueEmpty     
    ' Dump warning          
    'Session.Output(theElement.Name & " " & taggedValueName & " Value Missing")         
                else
                    TVGetElementTaggedValue = taggedValue.Value
                end if
            end if
        end if
    
    end function
    
    1. 最终印刷:

    2. Session.Output("Roles:   " + CStr(Roles))
      

      感谢您的帮助。

相关问题