Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AF SDK Reference

AFElementTemplate Class

  • Last UpdatedNov 18, 2025
  • 14 minute read
AFElementTemplate Class
The AFElementTemplate represents a template of information used to create an AFBaseElement. Several types of objects are elements, including an AFElement, AFEventFrame, or AFModel.

Inheritance Hierarchy

SystemObject
  OSIsoft.AFAFObject
    OSIsoft.AF.AssetAFElementTemplate
      OSIsoft.AF.NotificationAFNotificationTemplate

Namespace:  OSIsoft.AF.Asset
Assembly:  OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 3.1.1.1182

Syntax

[SerializableAttribute]
public class AFElementTemplate : AFObject, 
	IAFTransactable, IAFChangedEvent, IAFSecurable, IComparable<AFElementTemplate>
<SerializableAttribute>
Public Class AFElementTemplate
	Inherits AFObject
	Implements IAFTransactable, IAFChangedEvent, IAFSecurable, IComparable(Of AFElementTemplate)

Dim instance As AFElementTemplate
[SerializableAttribute]
public ref class AFElementTemplate : public AFObject, 
	IAFTransactable, IAFChangedEvent, IAFSecurable, IComparable<AFElementTemplate^>
[<SerializableAttribute>]
type AFElementTemplate =  
    class
        inherit AFObject
        interface IAFTransactable
        interface IAFChangedEvent
        interface IAFSecurable
        interface IComparable<AFElementTemplate>
    end

The AFElementTemplate type exposes the following members.

Constructors

  NameDescription
Public method
AFElementTemplate
Initializes a new instance of the class with default values.
Public method
AFElementTemplate(String)
Initializes a new instance of the class with the specified name.

Properties

  NameDescription
Public property
AllowElementToExtend
This read/write property determines if additional attributes or ports can be added to instances of AFBaseElement objects.
Public property
AnalysisTemplates
This is a collection of analysis templates that target this element template.
Public property
AttributeTemplates
Gets the collection of AFAttributeTemplate objects that are owned by this template.
Public property
BaseTemplate
This property returns the AFElementTemplate which this template inherits from.
Public property
BaseTemplateOnly
This read/write property determines if instances of this AFBaseElement object are allowed to be created. This is typically a BaseTemplate that contains some core functionality for other derived templates.
Public property
CanBeAcknowledged
This property is the default value for the CanBeAcknowledged property of any new AFEventFrame created from this template.
Public property
Categories
This is a user-defined collection of categories for the object that can be used for querying and/or reporting purposes.
Public property
CategoriesString
This read-only property returns the list of categories in a string separated by semicolons.
Public property
CheckOutInfo
This read-only property returns the checked out status information for the object.
Public property
ChildReferenceTypes
This is a read-only collection of all AFReferenceType objects that can be used to create a child reference to an AFElement created from this template.
Public property
Database
This read-only property returns the AFDatabase where this object is defined.
Public property
DefaultAttribute
The AFAttributeTemplate associated with the default AFAttribute for the AFBaseElement created from this template.
Public property
DefaultInputPort
The default input AFPort for the AFBaseElement created from this template.
Public property
DefaultOutputPort
The default output AFPort for the AFBaseElement created from this template.
Public property
DefaultUndirectedPort
The default undirected AFPort for the AFBaseElement created from this template.
Public property
Description
Read/write property that provides a more detailed description of the object.
Public property
ExtendedProperties
A dictionary of extended properties that can be used to store application specific information.
Public property
HasAnalyses
This read-only property returns if there are any AFAnalysisTemplate objects that target this element template.
Public property
HasNotifications
This read-only property returns if there are any AFNotificationTemplate objects that target this element template.
Public property
ID
Read-only property that provides a unique identifier for the object to be used for quick access that is not dependent upon the index.
(Inherited from AFObject.)
Public property
Identity
This read-only property contains identity of the object.
(Inherited from AFObject.)
Public property
InstanceType
Specifies the System.Type used when creating AFBaseElement objects from this template.
Public property
IsDeleted
This read-only property indicates whether the object has been deleted.
(Inherited from AFObject.)
Public property
IsDirty
This read-only property indicates whether the object has been modified since the last save to the PI AF Server.
Public property
IsNew
This read-only property indicates whether the object is new and has never been saved to the PI AF Server.
Public property
Name
Read/write property that identifies the name of the object.
Public property
NamingPattern
The naming pattern used when creating elements from this template.
Public propertyStatic member
None
An AFElementTemplate that represents no element template.
Public property
NotificationRuleTemplates
This is a collection of AFNotificationRuleTemplate objects that target this element template.
Public property
ParentReferenceTypes
This is a read-only collection of all AFReferenceType objects that can be used to create a parent reference to an AFElement created from this template.
Public property
PISystem
This read-only property allows access to the PISystem associated with this object.
(Inherited from AFObject.)
Public property
Ports
This is a collection of AFPort objects representing the possible connection ports for elements created from this template. Ports are used in a AFModel to define an AFConnection between AFBaseElement object.
Public property
Security
This read-only property returns the AFSecurity information for the object.
Public property
Severity
This property is the default value for the Severity property of any new AFEventFrame created from this template.
Public property
Type
This property specifies the base type of the element created from this template.
Public property
UniqueID
Read-only property that provides the object's ID as a String.
(Inherited from AFObject.)

Methods

  NameDescription
Public methodCode example
ApplyChanges
This method applies the changes to the object and makes those changes available to other objects for the current user.
Public methodCode example
CheckIn
This method checks in (commits) all the changes to the object by saving the information to persistent storage.
Public method
CheckOut
This method locks the object so that its configuration can be modified.
Public methodStatic member
CheckOutElementTemplates
Check out the objects with the specified unique identifiers at the specified query date.
Public method
CompareTo(Object)
Compares this instance with a specified Object.
(Inherited from AFObject.)
Public method
CompareTo(AFObject)
Compares this instance with a specified AFObject.
(Inherited from AFObject.)
Public method
CreateDefaultPorts
This method can be used to create the default connection ports based upon the element's type.
Public methodStatic member
DeleteElementTemplates
Delete the objects with the specified unique identifiers.
Public method
Equals(Object)
Determines whether the specified Object is equal to the current object.
(Inherited from AFObject.)
Public method
Equals(AFObject)
Indicates whether the current object is equal to another object of the same type.
(Inherited from AFObject.)
Public method
FindDerivedTemplates
This method returns the collection of AFElementTemplate objects that have this template as their base template.
Public methodStatic member
FindElementTemplate(PISystem, Guid)
Retrieves the AFElementTemplate object with the specified unique identifier at the AFTime.MaxValue query date.
Public methodStatic member
FindElementTemplate(PISystem, Guid, Object)
Retrieves the AFElementTemplate object with the specified unique identifier at the specified query date.
Public methodStatic member
FindElementTemplates(PISystem, Guid, Object)
Performs a search within the PISystem to retrieve a collection of AFElementTemplate objects with the specified list of unique identifiers.
Public methodStatic member
FindElementTemplates(AFDatabase, String, AFSearchField, AFSortField, AFSortOrder, Int32)
Performs a text search within the AFDatabase to retrieve a collection of AFElementTemplate objects which have a field that matches the specified query string.
Public method
FindInstantiatedElements(Boolean, AFSortField, AFSortOrder, Int32)
This method returns a non-paged collection of AFBaseElement objects that were created with this template.
Public method
FindInstantiatedElements(Boolean, AFSortField, AFSortOrder, Int32, Int32, Int32)
This method returns a paged collection of AFBaseElement objects that were created with this template.
Public method
GetAllAnalysisTemplates
Gets the list of analysis templates for this template and all base templates.
Public method
GetAllAttributeTemplates
Gets the list of top-level attribute templates for this template and all base templates.
Public method
GetAllCategories
Gets the list of categories for this template and all base templates.
Public method
GetAllCategoriesString
Gets the list of categories for this template and all base templates.
Public method
GetAllNotificationRuleTemplates
Gets the list of AFNotificationRuleTemplate objects for this template and all base templates.
Public method
GetAllPorts
Gets the list of ports for this template and all base templates.
Public method
GetAttributeTemplateByTrait
Retrieves the child AFAttributeTemplate with the specified AFAttributeTrait.
Public method
GetAttributeTemplatesByTrait
Retrieves a list of child AFAttributeTemplate objects identified by the specified list of attribute traits.
Public method
GetHashCode
Gets the hash code for this instance of the object which is suitable for use in hashing algorithms and data structures like a hash table.
(Inherited from AFObject.)
Public method
GetPath
Returns the full path to the object, using just the names.
(Inherited from AFObject.)
Public method
GetPath(AFObject)
Returns the path to the object relative from another object.
(Inherited from AFObject.)
Public method
GetPath(AFEncodeType, AFObject)
Returns the path to the object relative from another object, using the name and/or id as specified by encodeType.
(Inherited from AFObject.)
Public method
GetSecurity
Gets the AFSecurity information of the specified security item associated with the object.
Public method
GetType
Gets the Type of the current instance.
(Inherited from Object.)
Public method
IsTypeOf
Checks if the current AFElementTemplate is derived from the specified base element template.
Public methodStatic member
LoadElementTemplates(IListAFElementTemplate)
Loads the specified list AFElementTemplate objects.
Public methodStatic member
LoadElementTemplates(PISystem, Guid, Object)
Loads the AFElementTemplate objects with the specified unique identifiers at the specified query date.
Public method
Persist
This method returns the persistence string for the object.
(Inherited from AFObject.)
Public method
Refresh
Refreshes the client with any changes that have been made to the object since loaded.
Public method
ToString
Returns a String that represents the current object.
(Inherited from AFObject.)
Public method
UndoCheckOut
This method discards all the changes to the object and all sub-objects since the last call to CheckOut. Any changes since the check out will be lost.

Events

  NameDescription
Public eventCode example
Changed
Event is raised when the object or one of its sub-objects is changed.

Remarks

The template specifies the instance type of the AFBaseElement created from the template with its InstanceType property. An AFNotificationTemplate can be used to create an AFNotification and define its additional fields. The template also specifies the initial value of the AFBaseElement.Categories, and AFBaseElement.Attributes properties of the element created from it as well as the available ports for connecting elements within a model (see AFPort for more information). The template also defines the DefaultAttribute, DefaultInputPort, DefaultOutputPort, and DefaultUndirectedPort properties on any created elements.

The element template contains a collection of AFAttributeTemplate objects. This collection is used when creating the AFAttribute objects of an element. Attribute templates can be added or removed after elements have been created using the template, but it is more efficient to define them before creating elements. Changes made to the element template are propagated to any AFBaseElement objects created from the template when the ApplyChanges or CheckIn methods are called.

Element templates also support inheritance, which makes it easier to extend existing templates. The inheritance relationship is represented using the BaseTemplate property and the collection of derived templates returned by the FindDerivedTemplates(Boolean, AFSortField, AFSortOrder, Int32) method. A derived template can extend or override the attribute templates and ports defined by the base template.

Use a constructor or the Add method of the appropriate collection to create a new AFBaseElement object. For example, use one of the AFElements.Add Overload methods to create a new AFElement object or AFTransfer constructor to create a new AFTransfer object.

Examples

// This example demonstrates how to create an element template,
// create an element from it, and display its information.

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

// Create an Element Template
AFElementTemplate myElemTemplate = myDB.ElementTemplates.Add("MyElementTemplate");
myElemTemplate.Description = "Template used to create my elements";

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

// Display the name and description of the Element Template
Console.WriteLine("Name of Element Template = {0}", myElemTemplate.Name);
Console.WriteLine("Description = {0}", myElemTemplate.Description);
Console.WriteLine("UniqueID of Element Template = {0}", myElemTemplate.UniqueID);

// Display the name of all Elements created from this Element Template
const int pageSize = 100;
int startIndex = 0;
int totalCount;
do
{
    AFNamedCollectionList<AFBaseElement> list =
        myElemTemplate.FindInstantiatedElements(true, AFSortField.Name,
            AFSortOrder.Ascending, startIndex, pageSize, out totalCount);
    if (list == null) break;
    foreach (AFBaseElement CurElement in list)
    {
        Console.WriteLine("Name of Element created from this template = {0}", CurElement.Name);
    }

    startIndex += pageSize; // Advance to next page.
} while (startIndex < totalCount);
' This example demonstrates how to create an element template,
' create an element from it, and display its information.

' Get the Database
Dim myPISystems As New PISystems
Dim myDB As AFDatabase = myPISystems.DefaultPISystem.Databases.DefaultDatabase

' Create an Element Template
Dim myElemTemplate As AFElementTemplate = myDB.ElementTemplates.Add("MyElementTemplate")
myElemTemplate.Description = "Template used to create my elements"

' Create an Element from the Element Template
myDB.Elements.Add("MyElement", myElemTemplate)
myDB.CheckIn()

' Display the name and description of the Element Template
Console.WriteLine("Name of Element Template = {0}", myElemTemplate.Name)
Console.WriteLine("Description = {0}", myElemTemplate.Description)
Console.WriteLine("UniqueID = {0}", myElemTemplate.UniqueID)

' Display the name of all Elements created from this Element Template
Dim pageSize As Integer = 100
Dim startIndex As Integer = 0
Dim totalCount As Integer
Dim list As AFNamedCollectionList(Of AFBaseElement)
Do
    list = myElemTemplate.FindInstantiatedElements(True, AFSortField.Name, AFSortOrder.Descending,
                                                   startIndex, pageSize, totalCount)
    If (list Is Nothing) Then
        Exit Do
    End If

    Dim CurElement As AFBaseElement
    For Each CurElement In list
        Console.WriteLine("Name of Element created from this template = {0}", CurElement.Name)
    Next CurElement

    startIndex = (startIndex + pageSize)    ' Advance to next page
Loop While (startIndex < totalCount)

No code example is currently available or this language may not be supported.

No code example is currently available or this language may not be supported.

Version Information

AFSDK


See Also

TitleResults for “How to create a CRG?”Also Available in