Click or drag to resize
OSIsoft, LLC

PIPointGetAttributes Method

Get the list of PIPoint attribute values by name.

Namespace:  OSIsoft.AF.PI
Assembly:  OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 2.10.6.195
Syntax
public IDictionary<string, Object> GetAttributes(
	params string[] names
)

Parameters

names
Type: SystemString
The list of PIPoint attribute names of the values to be returned. The PICommonPointAttributes class contains some of the common PIPoint attribute names. If or an empty list, then all PIPoint attributes are returned.

Return Value

Type: IDictionaryString, Object
Returns a dictionary of the requested PIPoint attribute values. The dictionary key is the name of the PIPoint attribute and the dictionary value is the PIPoint attribute value.
Remarks
If the PIPoint attribute was previously loaded, then the cached value of the PIPoint attribute will be returned. If the requested attribute is not in the cache, then it is automatically read from the server.
Examples
// This example demonstrates how to create an attribute for an
// element and retrieve and set PIPoint attributes.

// Get the Database
PISystems myPISystems = new PISystems();
PISystem myPISystem = myPISystems.DefaultPISystem;
AFDatabase myDB = myPISystem.Databases.DefaultDatabase;

// Create an Element Template
AFElementTemplate myElemTemplate = myDB.ElementTemplates.Add("MyElementTemplate");
AFAttributeTemplate myAttrTemplate = myElemTemplate.AttributeTemplates.Add("Attr#1");
myAttrTemplate.DataReferencePlugIn = AFDataReference.GetPIPointDataReference(myPISystem);
myAttrTemplate.ConfigString = @"\\%Server%\%Element%;pointtype=Float64";

// Create an Element from the Element Template
AFElement myElement = myDB.Elements.Add("MyElement", myElemTemplate);

// Create the PIPoint for the Attribute
AFAttribute myAttribute = myElement.Attributes["Attr#1"];
myAttribute.DataReference.CreateConfig();

// Find all PIPoint Attributes and Display their values
object drAttrValue;
myAttribute.PIPoint.LoadAttributes();
IEnumerable<string> list = myAttribute.PIPoint.FindAttributeNames(null);
Console.WriteLine("Found PIPoint Attributes: nameFilter='<null>'");
foreach (string item in list)
{
    drAttrValue = myAttribute.PIPoint.GetAttribute(item);
    Console.WriteLine("  {0} = '{1}'", item, drAttrValue);
}
Console.WriteLine();

// Find PIPoint Attributes matching 'Ex*' and display their values
list = myAttribute.PIPoint.FindAttributeNames("Ex*");
Console.WriteLine("Found PIPoint Attributes: nameFilter='Ex*'");
int cnt = 0;
foreach (string item in list)
{
    cnt++;
    drAttrValue = myAttribute.PIPoint.GetAttribute(item);
    Console.WriteLine("  {0} = '{1}'", item, drAttrValue);
}
Console.WriteLine();

// Unload all PIPoint Attributes
myAttribute.PIPoint.UnloadAllAttributes();

// Load specific PIPoint Attributes and display their values
myAttribute.PIPoint.LoadAttributes(PICommonPointAttributes.PointType,
    PICommonPointAttributes.PointID,
    PICommonPointAttributes.Descriptor,
    PICommonPointAttributes.ExtendedDescriptor,
    PICommonPointAttributes.CreationDate);
drAttrValue = myAttribute.PIPoint.GetAttribute(PICommonPointAttributes.PointType);
Console.WriteLine("PIPoint Attribute '{0}' = '{1}'.", PICommonPointAttributes.PointType, drAttrValue);
drAttrValue = myAttribute.PIPoint.GetAttribute(PICommonPointAttributes.PointID);
Console.WriteLine("PIPoint Attribute '{0}' = '{1}'.", PICommonPointAttributes.PointID, drAttrValue);
drAttrValue = myAttribute.PIPoint.GetAttribute(PICommonPointAttributes.Descriptor);
Console.WriteLine("PIPoint Attribute '{0}' = '{1}'.", PICommonPointAttributes.Descriptor, drAttrValue);
drAttrValue = myAttribute.PIPoint.GetAttribute(PICommonPointAttributes.ExtendedDescriptor);
Console.WriteLine("PIPoint Attribute '{0}' = '{1}'.", PICommonPointAttributes.ExtendedDescriptor, drAttrValue);
drAttrValue = myAttribute.PIPoint.GetAttribute(PICommonPointAttributes.CreationDate);
Console.WriteLine("PIPoint Attribute '{0}' = '{1}'.", PICommonPointAttributes.CreationDate, drAttrValue);
Console.WriteLine();

// Set PIPoint Attribute value
string newAttrValue = "New Value: " + DateTime.Now.ToShortTimeString();
myAttribute.PIPoint.SetAttribute(PICommonPointAttributes.Descriptor, newAttrValue);
myAttribute.PIPoint.SetAttribute(PICommonPointAttributes.ExtendedDescriptor, newAttrValue);
AFErrors<string> errors = myAttribute.PIPoint.SaveAttributes(PICommonPointAttributes.Descriptor,
    PICommonPointAttributes.ExtendedDescriptor);
if (errors != null && errors.HasErrors)
{
    Console.WriteLine("Errors calling PIPoint.SaveAttributes:");
    foreach (var item in errors.Errors)
    {
        Console.WriteLine("  {0}: {1}", item.Key, item.Value);
    }
}
Version Information

AFSDK

Supported in: 2.10.5, 2.10, 2.9.5, 2.9, 2.8.5, 2.8, 2.7.5, 2.7, 2.6, 2.5
See Also
Enabling Operational Intelligence