I'm having trouble getting some of my Add In code to work, which should, whenever a new element is dragged and dropped from the Toolbox, automatically populate a Tagged Value called 'Analyst' with the name of the user.
The error message is :
EA_OnPostNewElement: Public member 'Analyst' on type IDualCollection' not found
This I assume means it can't find the Tagged Value but I even ran a simple diagnostic (the commented out Message Boxes) from the Add In and it's definitely present.
Ultimately I also want to populate other fields, such as Date, but let's not try to run too soon.
The code is as follows:
Function EA_OnPostNewElement(ByVal Repository As EA.Repository, ByVal Info As EA.EventProperties) As Object
Dim intPointer As Integer
Dim objElement As Object
Dim objTaggedValue As Object
Dim strReport As String
Dim strNumericOnly As String
Dim strTodaysDate As String = String.Format("{0:dd/MM/yyyy}", DateTime.Now)
Dim strUser As String = Environment.UserName
Dim nonAlphaChars As New System.Text.RegularExpressions.Regex("[^0-9]")
strReport = EventPropertiesToString(Info) 'get the element ID
strNumericOnly = nonAlphaChars.Replace(strReport, String.Empty) 'remove all non numeric characters
intPointer = CInt(strNumericOnly) 'and ensure that it's an integer
objElement = Repository.GetElementByID(intPointer)
'MsgBox(objElement.Name) this instruction used to prove that the appropriate element can be found
'in the repository
'For Each objTaggedValue In objElement.TaggedValues
' MsgBox(objTaggedValue.Name)
'Next
objElement.TaggedValues.Analyst = strUser
EA_OnPostNewElement = Nothing
End Function
I also want to do a simple check to ensure that an 'empty' Tagged Value is present in the collection for each element, and if not then add it, so I'd be most grateful for a clue how to do that.
I found the following from a Sparx publication to create a new Tagged Value but I was again getting error messages, and I'm uncertain whether AddNew is applicable to Tagged Value collections...
(I assume that 'Appended' is the Name of the Tagged Value, and 'Change' is the desired value, but maybe I've misunderstood the intent)
'TaggedValues
o = element.TaggedValues.AddNew("Appended","Change")
If not o.Update Then
Console.WriteLine("TaggedValues error:" + o.GetLastError())
End if
element.TaggedValues.Refresh
For idx = 0 to element.TaggedValues.Count -1
o = element.TaggedValues.GetAt(idx)
Console.WriteLine(o.Name)
If(o.Name="Appended") Then
If bDel Then element.TaggedValues.Delete (idx)
End if
Next
Many thanks in advance for any help received.