AFElementTemplate Class
- Last UpdatedNov 18, 2025
- 14 minute read
- PI System
- AF SDK 2024 R2
- Developer

Inheritance Hierarchy
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
| Name | Description | |
|---|---|---|
| AFElementTemplate |
Initializes a new instance of the class with default values.
| |
| AFElementTemplate(String) |
Initializes a new instance of the class with the specified name.
|
Properties
| Name | Description | |
|---|---|---|
| AllowElementToExtend |
This read/write property determines if additional attributes or ports can be added to
instances of AFBaseElement objects.
| |
| AnalysisTemplates |
This is a collection of analysis templates that target this element template.
| |
| AttributeTemplates |
Gets the collection of AFAttributeTemplate objects
that are owned by this template.
| |
| BaseTemplate |
This property returns the AFElementTemplate which this template inherits from.
| |
| 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.
| |
| CanBeAcknowledged |
This property is the default value for the CanBeAcknowledged
property of any new AFEventFrame created from this template.
| |
| Categories |
This is a user-defined collection of categories for the object that can be used for
querying and/or reporting purposes.
| |
| CategoriesString |
This read-only property returns the list of categories in a string separated by semicolons.
| |
| CheckOutInfo |
This read-only property returns the checked out status information for the object.
| |
| 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.
| |
| Database |
This read-only property returns the AFDatabase where this object is defined.
| |
| DefaultAttribute |
The AFAttributeTemplate associated with the default
AFAttribute for the AFBaseElement created from
this template.
| |
| DefaultInputPort |
The default input AFPort for the AFBaseElement
created from this template.
| |
| DefaultOutputPort |
The default output AFPort for the AFBaseElement
created from this template.
| |
| DefaultUndirectedPort |
The default undirected AFPort for the AFBaseElement
created from this template.
| |
| Description |
Read/write property that provides a more detailed description of the object.
| |
| ExtendedProperties |
A dictionary of extended properties that can be used to store application specific information.
| |
| HasAnalyses |
This read-only property returns if there are any
AFAnalysisTemplate objects that target this element template.
| |
| HasNotifications |
This read-only property returns if there are any
AFNotificationTemplate objects that target this element template.
| |
| 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.) | |
| Identity |
This read-only property contains identity of the object.
(Inherited from AFObject.) | |
| InstanceType |
Specifies the System.Type used when creating
AFBaseElement objects from this template.
| |
| IsDeleted |
This read-only property indicates whether the object has been deleted.
(Inherited from AFObject.) | |
| IsDirty |
This read-only property indicates whether the object has been modified since the
last save to the PI AF Server.
| |
| IsNew |
This read-only property indicates whether the object is new and has never been saved
to the PI AF Server.
| |
| Name |
Read/write property that identifies the name of the object.
| |
| NamingPattern |
The naming pattern used when creating elements from this template.
| |
| None |
An AFElementTemplate that represents no element template.
| |
| NotificationRuleTemplates |
This is a collection of AFNotificationRuleTemplate objects that target this element template.
| |
| 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.
| |
| PISystem |
This read-only property allows access to the PISystem associated with this
object.
(Inherited from AFObject.) | |
| 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.
| |
| Security |
This read-only property returns the AFSecurity information for the object.
| |
| Severity |
This property is the default value for the Severity
property of any new AFEventFrame created from this template.
| |
| Type |
This property specifies the base type of the element created from this template.
| |
| UniqueID |
Read-only property that provides the object's ID as a String.
(Inherited from AFObject.) |
Methods
| Name | Description | |
|---|---|---|
| ApplyChanges |
This method applies the changes to the object and makes
those changes available to other objects for the current user.
| |
| CheckIn |
This method checks in (commits) all the changes to the object by saving
the information to persistent storage.
| |
| CheckOut |
This method locks the object so that its configuration can be modified.
| |
| CheckOutElementTemplates |
Check out the objects with the specified unique identifiers at the specified query date.
| |
| CompareTo(Object) |
Compares this instance with a specified Object.
(Inherited from AFObject.) | |
| CompareTo(AFObject) |
Compares this instance with a specified AFObject.
(Inherited from AFObject.) | |
| CreateDefaultPorts |
This method can be used to create the default connection ports based upon the
element's type.
| |
| DeleteElementTemplates |
Delete the objects with the specified unique identifiers.
| |
| Equals(Object) |
Determines whether the specified Object is equal to the current object.
(Inherited from AFObject.) | |
| Equals(AFObject) |
Indicates whether the current object is equal to another object of the same type.
(Inherited from AFObject.) | |
| FindDerivedTemplates |
This method returns the collection of AFElementTemplate objects that
have this template as their base template.
| |
| FindElementTemplate(PISystem, Guid) |
Retrieves the AFElementTemplate object with the specified unique identifier
at the AFTime.MaxValue query date.
| |
| FindElementTemplate(PISystem, Guid, Object) |
Retrieves the AFElementTemplate object with the specified unique identifier
at the specified query date.
| |
| FindElementTemplates(PISystem, Guid, Object) |
Performs a search within the PISystem to retrieve a collection
of AFElementTemplate objects with the specified list of unique identifiers.
| |
| 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.
| |
| FindInstantiatedElements(Boolean, AFSortField, AFSortOrder, Int32) |
This method returns a non-paged collection of AFBaseElement objects that were
created with this template.
| |
| FindInstantiatedElements(Boolean, AFSortField, AFSortOrder, Int32, Int32, Int32) |
This method returns a paged collection of AFBaseElement objects that were
created with this template.
| |
| GetAllAnalysisTemplates |
Gets the list of analysis templates for this template and all base templates.
| |
| GetAllAttributeTemplates |
Gets the list of top-level attribute templates for this template and all base templates.
| |
| GetAllCategories |
Gets the list of categories for this template and all base templates.
| |
| GetAllCategoriesString |
Gets the list of categories for this template and all base templates.
| |
| GetAllNotificationRuleTemplates |
Gets the list of AFNotificationRuleTemplate objects for this template and all base templates.
| |
| GetAllPorts |
Gets the list of ports for this template and all base templates.
| |
| GetAttributeTemplateByTrait |
Retrieves the child AFAttributeTemplate with the specified AFAttributeTrait.
| |
| GetAttributeTemplatesByTrait |
Retrieves a list of child AFAttributeTemplate objects identified by the specified list of attribute traits.
| |
| 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.) | |
| GetPath |
Returns the full path to the object, using just the names.
(Inherited from AFObject.) | |
| GetPath(AFObject) |
Returns the path to the object relative from another object.
(Inherited from AFObject.) | |
| 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.) | |
| GetSecurity |
Gets the AFSecurity information of the specified security item
associated with the object.
| |
| GetType | Gets the Type of the current instance. (Inherited from Object.) | |
| IsTypeOf |
Checks if the current AFElementTemplate is derived from the
specified base element template.
| |
| LoadElementTemplates(IListAFElementTemplate) |
Loads the specified list AFElementTemplate objects.
| |
| LoadElementTemplates(PISystem, Guid, Object) |
Loads the AFElementTemplate objects with the specified unique identifiers
at the specified query date.
| |
| Persist |
This method returns the persistence string for the object.
(Inherited from AFObject.) | |
| Refresh |
Refreshes the client with any changes that have been made to the object since loaded.
| |
| ToString |
Returns a String that represents the current object.
(Inherited from AFObject.) | |
| 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
| Name | Description | |
|---|---|---|
| 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.