Ever wanted the Enums used in ProcessBook to be available in AF for your custom applications? Well RJK Solutions wanted the exact same thing and have the following solution for you to use...we did the hard work so you don't have to!
Firstly some small pre-work has to be done.
The type libraries for the ProcessBook Object and Symbol libraries need to become an assembly so we can use Reflection to load them in our .Net code. Once we have the assembly then we can look for the Enums and parse them.
To create the assemblies we are going to use the tool tlbimp (which as the name suggests is a type library importer) - you can read more about it on
MSDN.
Simply run a command that imports the relevant library and output to an assembly. In this example our PI Home directory is "C:\Program Files\PIPC\" so we run:
Code:
tlbimp "C:\Program Files\PIPC\ProcBook\PISymLib.tlb" /out:"C:\PISymLib.dll"
tlbimp "C:\Program Files\PIPC\ProcBook\PIObjLib.tlb" /out:"C:\PIObjLib.dll"
There we have it, 2 assemblies that we can load using Reflection in .Net. The following code demonstrates how to do exactly that:
Code:
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 oTyp.IsEnum Then
ParseEnums(oTyp.Name, oTyp)
End If
Catch ex As Exception
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)
Try
ES.Add(System.Enum.GetName(oEnum, n), n)
Catch ex As Exception
End Try
Next
ES.CheckIn()
End If
End Sub
The variable "myAFDB" is an AFDatabase object.
What you end up with is something like the following:

Principal Consultant
Real-Time Data Management @ Wipro Technologies