RJKSolutions

PbSymLib Enum's to AF Enumeration Sets

Discussion created by RJKSolutions on Jul 28, 2009
Latest reply on Jul 28, 2009 by spilon

I needed some (most) of the ProcessBook symbol type library Enum's in AF.  On the face of it, it is a lot of manual typing in but I am too lazy for that so automated it - took me a little while to come up with a plan but worth it.  Hopefully I have not done anything I shouldn't have - OSI feel free to slap my wrists.

 

Anyway, I took the pbsymlib.tlb and ran it through "tlbimp.exe" to produce an assembly, I then loaded the assembly using reflection to loop through each type to pick out the Enums and create an AF Enumeration Set for each one.  Result is the same sets exist in AF and ProcessBook, which will come in handy for some projects I have

 

If anyone needs some similar look how simple it is (and for the good of the community):

Private Sub Enums()
    Dim PBSymLibDLL As System.Reflection.Assembly = System.Reflection.Assembly.LoadFile("C:\Pbsymlib.dll")

    For Each oTyp As Type In PBSymLibDLL.GetTypes()
        Try
            If System.Enum.IsDefined(oTyp, System.Enum.GetValues(oTyp)(0)) Then
                ParseEnums(oTyp.Name, oTyp)
            End If
        Catch ex As Exception
            ' I know, I know, not the best way to check but it works.
        End Try
    Next
End Sub

Private Sub ParseEnums(ByVal sEnum As String, ByVal oEnum As System.Type)
    Dim ES As OSIsoft.AF.Asset.AFEnumerationSet = MyAFDB.EnumerationSets(sEnum)
    If ES Is Nothing Then
        ES = MyAFDB.EnumerationSets.Add(sEnum)
        Dim n As Object
        For Each n In System.Enum.GetValues(oEnum)
            ES.Add(System.Enum.GetName(oEnum, n), n)
        Next
        MyAFDB.CheckIn()
    End If
End Sub

Enjoy!

Outcomes