Sparx Systems Forum

Enterprise Architect => General Board => Topic started by: zalbina on September 14, 2012, 01:11:19 am

Title: Add New Tagged Value to the Attribute
Post by: zalbina on September 14, 2012, 01:11:19 am
Hello,

I'm trying to add some tagged value to an attribute usind API and VBA, but doing this: att.TaggedValues.AddNew "bla","bla" does not work. Even no errors. Should I use SQL for it?

Thanks
Title: Re: Add New Tagged Value to the Attribute
Post by: OpenIT Solutions on September 14, 2012, 02:02:05 am
I have this code for updating tagvalues:

Public Function addOrUpdateTaggedValue(myElement As EA.Element, tagName As String, tagValue As String) As EA.TaggedValue
    Dim currentTag As EA.TaggedValue

    'update all tagged values with the given name
    For Each currentTag In myElement.TaggedValues
        If currentTag.Name = tagName Then
            currentTag.Value = tagValue
            currentTag.Update
            Set addOrUpdateTaggedValue = currentTag
        End If
    Next
    'no tagged value found, so create it
    If addOrUpdateTaggedValue Is Nothing Then
        If Len(tagValue) > 256 Then
            Set addOrUpdateTaggedValue = myElement.TaggedValues.AddNew(tagName, "Memo")
        Else
            Set addOrUpdateTaggedValue = myElement.TaggedValues.AddNew(tagName, "String")
        End If
        
        addOrUpdateTaggedValue.Value = tagValue
        addOrUpdateTaggedValue.Update
    End If
End Function
Title: Re: Add New Tagged Value to the Attribute
Post by: Robert Sheridan on September 14, 2012, 02:52:07 am
There were some earlier posts around this.  Can not remember what the gotcha was off hand but I think the tagged value for an attribute is in a different bit of the object hierarchy (and with a different name) to element tagged values. If you check the help it tells you.
Title: Re: Add New Tagged Value to the Attribute
Post by: Geert Bellekens on September 14, 2012, 04:31:23 pm
No you shouldn't need to resort to SQL.
The code posted by OpenIT Solutions should work just fine (seems somehow familiar  ;))

Geert
Title: Re: Add New Tagged Value to the Attribute
Post by: zalbina on September 19, 2012, 04:30:36 pm
Thank you everyone for your replays :).
Title: Re: Add New Tagged Value to the Attribute
Post by: zalbina on September 19, 2012, 07:17:51 pm
This is, actually wrong:

Set addOrUpdateTaggedValue = myElement.TaggedValues.AddNew(tagName, "String")

Because this function returns EA.TaggedValue and AddNew function returns type Object. So, type mismatch. Is it possible to convert from one type to another in VBA?

Thanks.
Title: Re: Add New Tagged Value to the Attribute
Post by: Geert Bellekens on September 19, 2012, 07:37:02 pm
Try changing EA.TaggedValue in EA.AttributeTag

Geert
Title: Re: Add New Tagged Value to the Attribute
Post by: zalbina on September 19, 2012, 08:28:28 pm
Miracle. It does work when I've changed it to EA.AttributeTag.

Thanks a lot.