Skip to content

Instantly share code, notes, and snippets.

@ThinkCode
Last active July 7, 2020 08:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThinkCode/f77951af28ab41f975b35d0dac1c4a2e to your computer and use it in GitHub Desktop.
Save ThinkCode/f77951af28ab41f975b35d0dac1c4a2e to your computer and use it in GitHub Desktop.
import sys
import clr
sys.path.append(r'C:\Program Files (x86)\PIPC\AF\PublicAssemblies\4.0')
clr.AddReference('OSIsoft.AFSDK')
from OSIsoft.AF import *
from OSIsoft.AF.PI import *
from OSIsoft.AF.Asset import *
from OSIsoft.AF.Data import *
from OSIsoft.AF.Time import *
from OSIsoft.AF.UnitsOfMeasure import *
def security_attr(tag):
# Two examples of Attributes
attrPtSec = PICommonPointAttributes.PointSecurity
attrDataSec = PICommonPointAttributes.DataSecurity
#attrUnits = PICommonPointAttributes.EngineeringUnits
pt = PIPoint.FindPIPoint(piServer, tag)
#pt.LoadAttributes('PointSecurity', 'DataSecurity')
pt.LoadAttributes('ptsecurity', 'DataSecurity')
#current_value = pt.CurrentValue()
pointsecurity = pt.GetAttribute(attrPtSec)
datasecurity = pt.GetAttribute(attrDataSec)
print(pointsecurity + ' | Users: A(r)', '--', datasecurity + ' | Users: A(r)')
new_identity = ' | Users: A(r)'
if 'Merchant' in pointsecurity:
print("Pt Security Access in place already")
pass
else:
pointsecurity += new_identity
if 'Merchant' in datasecurity:
print("Data Security Access in place already")
pass
else:
datasecurity += new_identity
try:
pt.SetAttribute(PICommonPointAttributes.PointSecurity, pointsecurity)
pt.SetAttribute(PICommonPointAttributes.DataSecurity, datasecurity)
pt.SaveAttributes(PICommonPointAttributes.DataSecurity, PICommonPointAttributes.PointSecurity)
pointsecurity = pt.GetAttribute(attrPtSec)
datasecurity = pt.GetAttribute(attrDataSec)
return tag, "-->", "pt security - ", pointsecurity, "data security - ", datasecurity
#return pointsecurity
except:
return "ERROR ", tag, "pt security - ", pointsecurity, "data security - ", datasecurity
if __name__ == '__main__':
print("Welcome to PIthon - Tag security change")
# PI Data Archive
piServers = PIServers()
piServer = piServers.DefaultPIServer;
with open('tag_list.txt', 'r') as tags_to_change:
for tag in tags_to_change:
#print(tag)
tag = tag.strip()
pt = PIPoint.FindPIPoint(piServer, tag)
name = pt.Name.upper()
print('\nShowing PI Tag Current Value for {0}'.format(name))
current_value = pt.CurrentValue()
print( '{0}\'s Current Value: {1}'.format(name, current_value.Value))
print(security_attr(tag))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment