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

Inheritance Hierarchy
OSIsoft.AFAFObject
OSIsoft.AF.AssetAFBaseElement
OSIsoft.AF.AssetAFElement
OSIsoft.AF.ModelingAFModel
Namespace: OSIsoft.AF.Modeling
Assembly: OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 3.1.1.1182
Syntax
[SerializableAttribute] public sealed class AFModel : AFElement, IComparable<AFModel>
<SerializableAttribute> Public NotInheritable Class AFModel Inherits AFElement Implements IComparable(Of AFModel) Dim instance As AFModel
[SerializableAttribute] public ref class AFModel sealed : public AFElement, IComparable<AFModel^>
[<SealedAttribute>] [<SerializableAttribute>] type AFModel = class inherit AFElement interface IComparable<AFModel> end
The AFModel type exposes the following members.
Constructors
| Name | Description | |
|---|---|---|
| AFModel |
Initializes a new instance of the class with default values.
| |
| AFModel(String) |
Initializes a new instance of the class with the specified name.
| |
| AFModel(String, AFElementTemplate) |
Initializes a new instance of the class with the specified name.
|
Properties
| Name | Description | |
|---|---|---|
| Analyses |
This is a collection of analyses that target this element.
(Inherited from AFElement.) | |
| Attributes |
This is a collection of attributes that are owned by this element.
(Inherited from AFBaseElement.) | |
| Categories |
This is a user-defined collection of categories for the object that can be used for
querying and/or reporting purposes.
(Inherited from AFBaseElement.) | |
| CategoriesString |
This read-only property returns the list of categories in a string separated by semicolons.
(Inherited from AFBaseElement.) | |
| CheckOutInfo |
This read-only property returns the checked out status information for the object.
(Inherited from AFElement.) | |
| Connections |
This is a collection of connections between elements that have been added to the model.
| |
| Database |
This read-only property returns the AFDatabase where this object is defined.
(Inherited from AFBaseElement.) | |
| DefaultAttribute |
The default AFAttribute for the AFBaseElement.
(Inherited from AFBaseElement.) | |
| DefaultInputPort |
The default input AFPort for the AFBaseElement.
(Inherited from AFBaseElement.) | |
| DefaultOutputPort |
The default output AFPort for the AFBaseElement.
(Inherited from AFBaseElement.) | |
| DefaultUndirectedPort |
The default undirected AFPort for the AFBaseElement.
(Inherited from AFBaseElement.) | |
| Description |
Read/write property that provides a more detailed description of the object.
(Inherited from AFBaseElement.) | |
| Elements |
This is a collection of child elements that have been added to this element.
(Inherited from AFElement.) | |
| ExtendedProperties |
A dictionary of extended properties that can be used to store application specific information.
(Inherited from AFBaseElement.) | |
| HasAnalyses |
This read-only property returns if there are any
AFAnalysis objects that target this element.
(Inherited from AFElement.) | |
| HasChildren |
This read-only property returns if the element has child elements.
(Inherited from AFElement.) | |
| HasNotifications |
This read-only property returns if there are any
AFNotification objects that target this element.
(Inherited from AFElement.) | |
| 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.) | |
| IsAnnotated |
This property indicates whether this element has any annotations.
(Inherited from AFBaseElement.) | |
| 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.
(Inherited from AFElement.) | |
| IsNew |
This read-only property indicates whether the object is new and has never been saved
to the PI AF Server.
(Inherited from AFElement.) | |
| IsRoot |
This read-only property returns if the element is a member of the
AFDatabase.Elements collection.
(Inherited from AFElement.) | |
| Layers |
This is a collection of layers that keeps track of the elements on
each layer of the model.
| |
| Name |
Read/write property that identifies the name of the object.
(Inherited from AFBaseElement.) | |
| NotificationRules |
This is a collection of AFNotificationRule objects that target this element.
(Inherited from AFElement.) | |
| Parent |
This property returns the primary parent AFElement that owns the element if it
is referenced by another element.
(Inherited from AFElement.) | |
| Parents | Obsolete.
This is a collection of all AFElement objects that reference this element.
(Inherited from AFElement.) | |
| 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 this element.
Ports are used in a AFModel to define an AFConnection
between AFBaseElement object.
(Inherited from AFBaseElement.) | |
| QueryDate |
This read-only property returns the date used to retrieve the version of an object.
(Inherited from AFElement.) | |
| Security |
This read-only property returns the AFSecurity information for the object.
(Inherited from AFElement.) | |
| Template |
The AFElementTemplate that was used to define this object.
(Inherited from AFBaseElement.) | |
| Type |
This property specifies the base type of the element.
(Inherited from AFElement.) | |
| UniqueID |
Read-only property that provides the object's ID as a String.
(Inherited from AFObject.) | |
| Version |
This read-only property returns the current version information as an
AFVersion object.
(Inherited from AFElement.) |
Methods
| Name | Description | |
|---|---|---|
| ApplyChanges |
This method applies the changes to the object and makes
those changes available to other objects for the current user.
(Inherited from AFElement.) | |
| ApplyQueryDate |
Applies the specified query date to the current object and returns an object in the new context.
(Inherited from AFElement.) | |
| ChangeReferenceType |
Change the existing AFReferenceType between a child element or the AFDatabase.
(Inherited from AFElement.) | |
| CheckIn |
This method checks in (commits) all the changes to the object by saving
the information to persistent storage.
(Inherited from AFElement.) | |
| CheckOut |
This method locks the object so that its configuration can be modified.
(Inherited from AFElement.) | |
| CompareTo(Object) |
Compares this instance with a specified Object.
(Inherited from AFObject.) | |
| CompareTo(AFObject) |
Compares this instance with a specified AFObject.
(Inherited from AFObject.) | |
| ConvertTo |
Converts the current object to the specified type of an AFElement.
(Inherited from AFElement.) | |
| CreateDefaultPorts |
This method can be used to create the default connection ports based upon the
element's type.
(Inherited from AFElement.) | |
| CreateElementTemplate |
Create an AFElementTemplate based upon the element.
(Inherited from AFBaseElement.) | |
| Delete |
Deletes all versions of this element from the AFDatabase.
(Inherited from AFElement.) | |
| 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.) | |
| FindModels |
Performs a non-paged text search within the AFDatabase to retrieve a collection
of AFModel objects which have a field that match the specified query string.
| |
| GetAnalyses | Obsolete.
Retrieves a collection of AFAnalysis objects that target this element.
(Inherited from AFElement.) | |
| GetAnnotations |
Retrieves a collection of existing AFAnnotation objects belonging to this
AFBaseElement.
(Inherited from AFBaseElement.) | |
| GetAttributeByTrait |
Retrieves the child AFAttribute with the specified AFAttributeTrait.
(Inherited from AFBaseElement.) | |
| GetAttributesByTrait |
Retrieves a list of child AFAttribute objects identified by the specified list of attribute traits.
(Inherited from AFBaseElement.) | |
| GetConnectedElements(AFElement) |
This method returns a collection of AFElement objects which are
connected to the specified element (or child element) within the model.
| |
| GetConnectedElements(AFElement, AFPortType) |
This method returns a collection of AFElement objects which are
connected to the specified element (or child element) through a port of the specified
type within the model.
| |
| GetConnectedElements(AFElement, String) |
This method returns a collection of AFElement objects which are
connected to the specified element and port within the model.
| |
| GetConnections(AFElement) |
This method returns a collection of AFConnection objects representing
a connection between the specified element (or child element) and another element
within the model.
| |
| GetConnections(AFElement, AFPortType) |
This method returns a collection of AFConnection objects with the
specified port type representing a connection between the specified element (or
child element) and another element within the model.
| |
| GetConnections(AFElement, String) |
This method returns a collection of AFConnection objects with the
specified port name representing a connection between the specified element and
another element within the model.
| |
| GetElements(AFSortField, AFSortOrder, Int32) | Obsolete.
Retrieves a non-paged collection of child AFElement objects that have been added
to this element.
(Inherited from AFElement.) | |
| GetElements(AFSortField, AFSortOrder, Int32, Int32, Int32) | Obsolete.
Retrieves a paged collection of child AFElement objects that have been added
to this element.
(Inherited from AFElement.) | |
| GetEventFrames(Object, Int32, Int32, AFEventFrameSearchMode, String, AFCategory, AFElementTemplate) | Obsolete.
Retrieves a paged collection of AFEventFrame objects that reference this element
limited to the specified count beginning at the requested start time in the specified direction.
(Inherited from AFElement.) | |
| GetEventFrames(AFSearchMode, Object, Object, String, AFCategory, AFElementTemplate, AFSortField, AFSortOrder, Int32, Int32) | Obsolete.
Retrieves a paged collection of AFEventFrame objects that reference this element
within the specified time range.
(Inherited from AFElement.) | |
| 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.) | |
| GetLayers |
This method returns a collection of AFLayer objects for the
specified element representing all the layers of the model which contain the
element.
| |
| GetNotifications |
Retrieves a collection of AFNotification objects that target this element.
(Inherited from AFElement.) | |
| GetParents(AFSortField, AFSortOrder, Int32) |
Retrieves a non-paged collection of AFElement objects that reference this element.
(Inherited from AFElement.) | |
| GetParents(AFCategory, AFSortField, AFSortOrder, Int32) |
Retrieves a non-paged collection of AFElement objects that reference this element
using the specified AFCategory.
(Inherited from AFElement.) | |
| GetParents(AFReferenceType, AFSortField, AFSortOrder, Int32) |
Retrieves a non-paged collection of AFElement objects that reference this element
using the specified AFReferenceType.
(Inherited from AFElement.) | |
| GetParents(AFSortField, AFSortOrder, Int32, Int32, Int32) |
Retrieves a paged collection of AFElement objects that reference this element.
(Inherited from AFElement.) | |
| GetParents(AFCategory, AFSortField, AFSortOrder, Int32, Int32, Int32) |
Retrieves a paged collection of AFElement objects that reference this element
using the specified AFCategory.
(Inherited from AFElement.) | |
| GetParents(AFReferenceType, AFSortField, AFSortOrder, Int32, Int32, Int32) |
Retrieves a paged collection of AFElement objects that reference this element
using the specified AFReferenceType.
(Inherited from AFElement.) | |
| 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.) | |
| GetPaths |
Get all the full paths to this AFElement.
(Inherited from AFElement.) | |
| GetPaths(String) |
Get all the relative paths to this AFElement.
(Inherited from AFElement.) | |
| GetReferenceTypes |
Retrieves a collection of all AFReferenceType objects that represent types
of references from this element to its child elements.
(Inherited from AFElement.) | |
| GetReferenceTypes(AFElement) |
Retrieves a collection of AFReferenceType objects that represent types
of references between this element and the specified related element.
(Inherited from AFElement.) | |
| GetSecurity |
Gets the AFSecurity information of the specified security item
associated with the object.
(Inherited from AFElement.) | |
| GetType | Gets the Type of the current instance. (Inherited from Object.) | |
| IsTypeOf |
Checks if the current AFBaseElement is derived from the
specified AFElementTemplate.
(Inherited from AFBaseElement.) | |
| 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.
(Inherited from AFElement.) | |
| 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.
(Inherited from AFElement.) |
Events
| Name | Description | |
|---|---|---|
| Changed |
Event is raised when the object or one of its sub-objects is changed.
(Inherited from AFElement.) |
Remarks
You can convert an existing element to a model by using the ConvertTo(Type) method. The same method can be used to convert a model back to an element.
Any existing elements can be added to this model using the AFElements.Add(AFElement) method. New elements can be added to this model using the AFElements.Add(string,AFElementTemplate) method. Connections between two elements added to the model can be created by calling the Add method of the Connections collection. Layers can also be created for the model (using the AFLayers.Add method).
After all the elements have been placed on the model and their connectivity is complete, you can run an analysis of the model. The AFDatabase.Analyses.Add Overload methods are used to create a new analysis.
A model inherits from AFElement and implements the IAFVersionable interface which supports creating versions. The Connections and Layers collections are the only additional items from an element that are specific to a version of the object.
| Using object versions can be expensive in memory usage and performance. Extra memory is required to store the versions in the server and for each version of the object loaded in the client. Performance is degraded because of the extra data to be searched in the server and returned back to the client. |
Use the PISystem.Supports method to check if the PISystem supports the Model feature.
Examples
// This example demonstrates how to create a model, add elements, connect the elements, // display model information, disconnect the elements, and finally remove the model. // Get the Database PISystems myPISystems = new PISystems(); AFDatabase myDB = myPISystems.DefaultPISystem.Databases.DefaultDatabase; // Create Elements AFElement srcElement = myDB.Elements.Add("srcElement"); srcElement.Ports.Add("Out", "source output port", AFPortType.Output, true); AFElement flowElement = myDB.Elements.Add("flowElement"); flowElement.Ports.Add("In", "flow input port", AFPortType.Input, true); flowElement.Ports.Add("Out", "flow output port", AFPortType.Output, true); AFElement destElement = myDB.Elements.Add("destElement"); destElement.Ports.Add("In", "destination input port", AFPortType.Input, true); // Create a Model AFElementTemplate modelTempl = myDB.ElementTemplates.Add("ModelTemplate"); modelTempl.InstanceType = typeof(AFModel); AFModel myModel = myDB.Elements.Add("MyModel", modelTempl) as AFModel; myModel.Description = "This Model represents a manufacturing facility"; myDB.ApplyChanges(); // Add Elements to Model myModel.Elements.Add(srcElement); myModel.Elements.Add(flowElement); myModel.Elements.Add(destElement); // Connect the Elements AFConnection conn1 = myModel.Connections.Add(srcElement.DefaultOutputPort, flowElement.DefaultInputPort); AFConnection conn2 = myModel.Connections.Add(flowElement.DefaultOutputPort, destElement.DefaultInputPort); // Display Model Information Console.WriteLine("Model Name = {0}", myModel.Name); Console.WriteLine("Description = {0}", myModel.Description); Console.WriteLine("Number of Elements = {0}", myModel.Elements.Count);
' This example demonstrates how to create a model, add elements, connect the elements, ' display model information, disconnect the elements, and finally remove the model. ' Get the Database Dim myPISystems As New PISystems Dim myDB As AFDatabase = myPISystems.DefaultPISystem.Databases.DefaultDatabase ' Create Elements Dim srcElement As AFElement = myDB.Elements.Add("srcElement") srcElement.Ports.Add("Out", "source output port", AFPortType.Output, True) Dim flowElement As AFElement = myDB.Elements.Add("flowElement") flowElement.Ports.Add("In", "flow input port", AFPortType.Input, True) flowElement.Ports.Add("Out", "flow output port", AFPortType.Output, True) Dim destElement As AFElement = myDB.Elements.Add("destElement") destElement.Ports.Add("In", "destination input port", AFPortType.Input, True) ' Create a Model Dim modelTempl As AFElementTemplate = myDB.ElementTemplates.Add("ModelTemplate") modelTempl.InstanceType = GetType(AFModel) Dim myModel As AFModel = CType(myDB.Elements.Add("MyModel", modelTempl), AFModel) myModel.Description = "This Model represents a manufacturing facility" myDB.ApplyChanges() ' Add Elements to Model myModel.Elements.Add(srcElement) myModel.Elements.Add(flowElement) myModel.Elements.Add(destElement) ' Connect the Elements Dim conn1 As AFConnection = myModel.Connections.Add(srcElement.DefaultOutputPort, flowElement.DefaultInputPort) Dim conn2 As AFConnection = myModel.Connections.Add(flowElement.DefaultOutputPort, destElement.DefaultInputPort) ' Display Model Information Console.WriteLine("Model Name = {0}", myModel.Name) Console.WriteLine("Description = {0}", myModel.Description) Console.WriteLine("Number of Elements = {0}", myModel.Elements.Count)
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.