9 Replies Latest reply on Apr 25, 2014 2:18 PM by David Hearn

    StateSets to EnumerationSets

      One of those code snippets others may find useful...I wanted the PI Server StateSets in AF.  At this point I don't need to keep them in sync with the PI server nor consider multiple PI server StateSets in a single AFDatabase, that will come later I am sure.

      Private Sub MoveStatesetsToAF(ByVal AF As OSIsoft.AF.AFDatabase, ByVal PI As PISDK.Server)

          Dim SS As PISDK.StateSet = Nothing
          Dim DS As PISDK.DigitalState = Nothing
          Dim ES As OSIsoft.AF.Asset.AFEnumerationSet = Nothing

          For Each SS In PI.StateSets
              ES = AF.EnumerationSets(SS.Name)
              If ES Is Nothing Then
                  ES = AF.EnumerationSets.Add(SS.Name)

                  For i As Integer = 0 To SS.Count - 1
                      DS = SS.Item(i)
                      ES.Add(DS.Name, DS.Code)
                  Next

                  ES.CheckIn()
              End If
          Next
      End Sub