AnsweredAssumed Answered

Python and PI AF SDK - How to Set UOM?

Question asked by Mattpdrexel on Nov 28, 2018
Latest reply on Nov 28, 2018 by Mattpdrexel

I'm a new PI AF SDK user interested in being able to create PI AF elements/attributes in Python.

Good instructions on how to get started are located here:

Python 3.6 and AFSDK example (PIthon!)


However, I am stuck on how to create a new PI AF attribute with a specified Default UOM (Unit of Measure).


I have attempted to run the code below, but I get an error message stating

'str' value cannot be converted to OSIsoft.AF.UnitsOfMeasure.UOM


Basically, I am not sure what the proper syntax is for setting the Default unit of measure in the PI AF SDK.


Any suggestions would be highly appreciated.





#create element with attribute  
print('\nCreate Element with Attribute')  
if DB.Elements.get_Item("Test New Element") is not None:  
    print("Already Existing Element: Test New Element")  
    newelement = DB.Elements.Add("Test New Element")  
    newelement.Description = "Created element from PIthon"  
    newattribute = newelement.Attributes.Add("Test Attribute")  
    newattribute.DataReferencePlugIn = afServer.DataReferencePlugIns.get_Item("PI Point")  
    newattribute.DataReference.ConfigString = "cdt158"
    newattribute.DefaultUOM = '°F'
    print("Created new Element : Test New Element")  


Error Message:



TypeError  Traceback (most recent call last)

<ipython-input-14-a87fc1f3b3a8> in <module>()

  9  newattribute.DataReferencePlugIn = afServer.DataReferencePlugIns.get_Item("PI Point")

  10  newattribute.DataReference.ConfigString = "cdt158"

---> 11   newattribute.DefaultUOM = '°F'

  12  DB.CheckIn()

  13  print("Created new Element : Test New Element")


TypeError: 'str' value cannot be converted to OSIsoft.AF.UnitsOfMeasure.UOM