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

AF SDK Reference

AFModel Class

  • Last UpdatedNov 18, 2025
  • 16 minute read
AFModel Class
The AFModel is a logical grouping of elements and their relationship (or connectivity) to other elements within the model.

Inheritance Hierarchy

SystemObject
  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

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

Properties

  NameDescription
Public property
Analyses
This is a collection of analyses that target this element.
(Inherited from AFElement.)
Public property
Attributes
This is a collection of attributes that are owned by this element.
(Inherited from AFBaseElement.)
Public property
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.)
Public property
CategoriesString
This read-only property returns the list of categories in a string separated by semicolons.
(Inherited from AFBaseElement.)
Public property
CheckOutInfo
This read-only property returns the checked out status information for the object.
(Inherited from AFElement.)
Public property
Connections
This is a collection of connections between elements that have been added to the model.
Public property
Database
This read-only property returns the AFDatabase where this object is defined.
(Inherited from AFBaseElement.)
Public property
DefaultAttribute
The default AFAttribute for the AFBaseElement.
(Inherited from AFBaseElement.)
Public property
DefaultInputPort
The default input AFPort for the AFBaseElement.
(Inherited from AFBaseElement.)
Public property
DefaultOutputPort
The default output AFPort for the AFBaseElement.
(Inherited from AFBaseElement.)
Public property
DefaultUndirectedPort
The default undirected AFPort for the AFBaseElement.
(Inherited from AFBaseElement.)
Public property
Description
Read/write property that provides a more detailed description of the object.
(Inherited from AFBaseElement.)
Public property
Elements
This is a collection of child elements that have been added to this element.
(Inherited from AFElement.)
Public property
ExtendedProperties
A dictionary of extended properties that can be used to store application specific information.
(Inherited from AFBaseElement.)
Public property
HasAnalyses
This read-only property returns if there are any AFAnalysis objects that target this element.
(Inherited from AFElement.)
Public property
HasChildren
This read-only property returns if the element has child elements.
(Inherited from AFElement.)
Public property
HasNotifications
This read-only property returns if there are any AFNotification objects that target this element.
(Inherited from AFElement.)
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
IsAnnotated
This property indicates whether this element has any annotations.
(Inherited from AFBaseElement.)
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.
(Inherited from AFElement.)
Public property
IsNew
This read-only property indicates whether the object is new and has never been saved to the PI AF Server.
(Inherited from AFElement.)
Public property
IsRoot
This read-only property returns if the element is a member of the AFDatabase.Elements collection.
(Inherited from AFElement.)
Public property
Layers
This is a collection of layers that keeps track of the elements on each layer of the model.
Public property
Name
Read/write property that identifies the name of the object.
(Inherited from AFBaseElement.)
Public property
NotificationRules
This is a collection of AFNotificationRule objects that target this element.
(Inherited from AFElement.)
Public property
Parent
This property returns the primary parent AFElement that owns the element if it is referenced by another element.
(Inherited from AFElement.)
Public property
Parents Obsolete.
This is a collection of all AFElement objects that reference this element.
(Inherited from AFElement.)
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 this element. Ports are used in a AFModel to define an AFConnection between AFBaseElement object.
(Inherited from AFBaseElement.)
Public property
QueryDate
This read-only property returns the date used to retrieve the version of an object.
(Inherited from AFElement.)
Public property
Security
This read-only property returns the AFSecurity information for the object.
(Inherited from AFElement.)
Public property
Template
The AFElementTemplate that was used to define this object.
(Inherited from AFBaseElement.)
Public property
Type
This property specifies the base type of the element.
(Inherited from AFElement.)
Public property
UniqueID
Read-only property that provides the object's ID as a String.
(Inherited from AFObject.)
Public property
Version
This read-only property returns the current version information as an AFVersion object.
(Inherited from AFElement.)

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.
(Inherited from AFElement.)
Public method
ApplyQueryDate
Applies the specified query date to the current object and returns an object in the new context.
(Inherited from AFElement.)
Public method
ChangeReferenceType
Change the existing AFReferenceType between a child element or the AFDatabase.
(Inherited from AFElement.)
Public methodCode example
CheckIn
This method checks in (commits) all the changes to the object by saving the information to persistent storage.
(Inherited from AFElement.)
Public method
CheckOut
This method locks the object so that its configuration can be modified.
(Inherited from AFElement.)
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 methodCode example
ConvertTo
Converts the current object to the specified type of an AFElement.
(Inherited from AFElement.)
Public method
CreateDefaultPorts
This method can be used to create the default connection ports based upon the element's type.
(Inherited from AFElement.)
Public method
CreateElementTemplate
Create an AFElementTemplate based upon the element.
(Inherited from AFBaseElement.)
Public method
Delete
Deletes all versions of this element from the AFDatabase.
(Inherited from AFElement.)
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 methodStatic member
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.
Public method
GetAnalyses Obsolete.
Retrieves a collection of AFAnalysis objects that target this element.
(Inherited from AFElement.)
Public method
GetAnnotations
Retrieves a collection of existing AFAnnotation objects belonging to this AFBaseElement.
(Inherited from AFBaseElement.)
Public method
GetAttributeByTrait
Retrieves the child AFAttribute with the specified AFAttributeTrait.
(Inherited from AFBaseElement.)
Public method
GetAttributesByTrait
Retrieves a list of child AFAttribute objects identified by the specified list of attribute traits.
(Inherited from AFBaseElement.)
Public method
GetConnectedElements(AFElement)
This method returns a collection of AFElement objects which are connected to the specified element (or child element) within the model.
Public method
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.
Public method
GetConnectedElements(AFElement, String)
This method returns a collection of AFElement objects which are connected to the specified element and port within the model.
Public method
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.
Public method
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.
Public method
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.
Public method
GetElements(AFSortField, AFSortOrder, Int32) Obsolete.
Retrieves a non-paged collection of child AFElement objects that have been added to this element.
(Inherited from AFElement.)
Public method
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.)
Public method
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.)
Public method
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.)
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
GetLayers
This method returns a collection of AFLayer objects for the specified element representing all the layers of the model which contain the element.
Public method
GetNotifications
Retrieves a collection of AFNotification objects that target this element.
(Inherited from AFElement.)
Public method
GetParents(AFSortField, AFSortOrder, Int32)
Retrieves a non-paged collection of AFElement objects that reference this element.
(Inherited from AFElement.)
Public method
GetParents(AFCategory, AFSortField, AFSortOrder, Int32)
Retrieves a non-paged collection of AFElement objects that reference this element using the specified AFCategory.
(Inherited from AFElement.)
Public method
GetParents(AFReferenceType, AFSortField, AFSortOrder, Int32)
Retrieves a non-paged collection of AFElement objects that reference this element using the specified AFReferenceType.
(Inherited from AFElement.)
Public method
GetParents(AFSortField, AFSortOrder, Int32, Int32, Int32)
Retrieves a paged collection of AFElement objects that reference this element.
(Inherited from AFElement.)
Public method
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.)
Public method
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.)
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
GetPaths
Get all the full paths to this AFElement.
(Inherited from AFElement.)
Public method
GetPaths(String)
Get all the relative paths to this AFElement.
(Inherited from AFElement.)
Public method
GetReferenceTypes
Retrieves a collection of all AFReferenceType objects that represent types of references from this element to its child elements.
(Inherited from AFElement.)
Public method
GetReferenceTypes(AFElement)
Retrieves a collection of AFReferenceType objects that represent types of references between this element and the specified related element.
(Inherited from AFElement.)
Public method
GetSecurity
Gets the AFSecurity information of the specified security item associated with the object.
(Inherited from AFElement.)
Public method
GetType
Gets the Type of the current instance.
(Inherited from Object.)
Public method
IsTypeOf
Checks if the current AFBaseElement is derived from the specified AFElementTemplate.
(Inherited from AFBaseElement.)
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.
(Inherited from AFElement.)
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.
(Inherited from AFElement.)

Events

  NameDescription
Public eventCode example
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.

Caution note Caution
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.

Version Information

AFSDK


See Also

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