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

AF SDK Reference

AFConnections Class

  • Last UpdatedNov 18, 2025
  • 8 minute read
AFConnections Class
The collection of AFConnection objects is maintained by an AFModel or AFCase.

Inheritance Hierarchy

SystemObject
  OSIsoft.AFAFCollection
    OSIsoft.AFAFCollectionAFConnection
      OSIsoft.AF.ModelingAFConnections

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

Syntax

public sealed class AFConnections : AFCollection<AFConnection>
Public NotInheritable Class AFConnections
	Inherits AFCollection(Of AFConnection)

Dim instance As AFConnections
public ref class AFConnections sealed : public AFCollection<AFConnection^>
[<SealedAttribute>]
type AFConnections =  
    class
        inherit AFCollection<AFConnection>
    end

The AFConnections type exposes the following members.

Properties

  NameDescription
Public property
Count
Gets the number of items actually contained in the collection.
(Inherited from AFCollectionT.)
Public property
Database
This read-only property returns the AFDatabase where this object is defined.
Public property
Identity
This read-only property contains identity of the object.
(Inherited from AFCollection.)
Public property
IsDeleted
This read-only property indicates whether the owner of the collection has been deleted.
(Inherited from AFCollection.)
Public property
ItemGuid
Returns the item in the collection associated with the passed in ID.
(Inherited from AFCollectionT.)
Public property
ItemInt32
Returns the item located at the passed in index.
(Inherited from AFCollectionT.)
Public property
ItemIdentity
This read-only property specifies the identity of the objects within the collection.
(Inherited from AFCollection.)
Public property
Model
This property returns the AFModel object which owns this collection.
Public property
PISystem
This read-only property allows access to the PISystem associated with this collection.
(Inherited from AFCollection.)

Methods

  NameDescription
Public method
Add(T)
Adds an object to the end of the collection.
(Inherited from AFCollectionT.)
Public method
Add(AFPort, AFPort)
The Add method creates a new connection between ports of two elements in the model.
Public method
Add(AFElement, AFPort, AFElement, AFPort) Obsolete.
The Add method creates a new connection between ports of two elements in the model.
Public method
Clear
Removes all items from the collection.
(Inherited from AFCollectionT.)
Public method
Contains(Guid)
This method determines whether the collection contains a specific item referenced by id.
(Inherited from AFCollectionT.)
Public method
Contains(T)
This method determines whether the collection contains a specific item.
(Inherited from AFCollectionT.)
Public method
CopyTo
Copies the entire collection to a compatible one-dimensional Array, starting at the specified index of the target array.
(Inherited from AFCollectionT.)
Public method
Equals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public method
GetEnumerator
Returns an enumerator that iterates through the collection.
(Inherited from AFCollectionT.)
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 AFCollection.)
Public method
GetType
Gets the Type of the current instance.
(Inherited from Object.)
Public method
IndexOf
Searches for the specified object and returns the zero-based index of the first occurrence within the entire collection.
(Inherited from AFCollectionT.)
Public method
IsValidConnection(Boolean, Boolean, AFPort, AFPort, String)
This method checks if a valid connection can be created between the specified source and destination ports of an AFBaseElement.
Public method
IsValidConnection(Boolean, Boolean, AFElement, AFPort, AFElement, AFPort, String) Obsolete.
This method checks if a valid connection can be created between the specified source and destination ports.
Public method
IsValidConnection(Boolean, Boolean, AFElementTemplate, AFPort, AFElementTemplate, AFPort, String)
This method checks if a valid connection can be created between the specified source and destination ports of an AFElementTemplate or AFBaseElement.
Public method
Remove(Guid)
Removes the item with the specified id from the collection.
(Inherited from AFCollectionT.)
Public method
Remove(T)
Removes the first occurrence of a specific object from the collection.
(Inherited from AFCollectionT.)
Public method
RemoveAt
Removes the item at the specified index of the collection.
(Inherited from AFCollectionT.)
Public method
Sort
Sorts the items in the entire collection using the default comparer.
(Inherited from AFCollectionT.)
Public method
Sort(IComparerT)
Sorts the items in the entire collection using the specified comparer.
(Inherited from AFCollectionT.)
Public method
Sort(Int32, Int32, IComparerT)
Sorts the items in a range of items in the collection using the specified comparer.
(Inherited from AFCollectionT.)
Public method
ToString
Returns a String that represents the current object.
(Inherited from AFCollection.)

Remarks

Several connections can be made to the same port of an element. A connection is created by calling one of the Add Overload methods and specifying the elements and ports to be connected.

Examples

// This example demonstrates how to connect and disconnect elements.
// Note: This example assumes that there is a database called "Chocolate Milk Tutorial"
// containing elements named "MilkTank1" and "MilkTank2" each with input/output ports,
// as well as an ElementTemplate named "Flow"

// Get the Database
PISystems myPISystems = new PISystems();
AFDatabase myDB = myPISystems.DefaultPISystem.Databases["Chocolate Milk Tutorial"];

// 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";

// Get the Elements
AFElement srcElement = myDB.Elements["MilkTank1"];
AFElement destElement = myDB.Elements["MilkTank2"];
AFElement flowElement = myDB.Elements.Add("Flow", myDB.ElementTemplates["Flow"]);
myDB.ApplyChanges();

// Add Elements to Model
myModel.Elements.Add(srcElement);
myModel.Elements.Add(destElement);
myModel.Elements.Add(flowElement);

// Connect the Elements
AFConnection conn1 = myModel.Connections.Add(srcElement.DefaultOutputPort,
    flowElement.DefaultInputPort);
AFConnection conn2 = myModel.Connections.Add(flowElement.DefaultOutputPort,
    destElement.DefaultInputPort);

// Display Information about each Connection
Console.WriteLine("Connection Count = {0}", myModel.Connections.Count);
foreach (AFConnection CurConn in myModel.Connections)
{
    Console.WriteLine("Name of Model = {0}", CurConn.Model.Name);
    Console.WriteLine("Source = {0}", CurConn.Source);
    Console.WriteLine("Source Port = {0}", CurConn.SourcePort);
    Console.WriteLine("Destination = {0}", CurConn.Destination);
    Console.WriteLine("Destination Port = {0}", CurConn.DestinationPort);
}
' This example demonstrates how to connect and disconnect elements.
' Note: This example assumes that there Is a database called "Chocolate Milk Tutorial"
' containing elements named "MilkTank1" And "MilkTank2" each with input/output ports,
' as well as an ElementTemplate named "Flow"

' Get the Database
Dim myPISystems As New PISystems
Dim myDB As AFDatabase = myPISystems.DefaultPISystem.Databases("Chocolate Milk Tutorial")

' 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"

' Get the Elements
Dim srcElement As AFElement = myDB.Elements("MilkTank1")
Dim destElement As AFElement = myDB.Elements("MilkTank2")
Dim flowElement As AFElement = myDB.Elements.Add("Flow", myDB.ElementTemplates("Flow"))
myDB.ApplyChanges()

' Add Elements to Model
myModel.Elements.Add(srcElement)
myModel.Elements.Add(destElement)
myModel.Elements.Add(flowElement)

' 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 Information about each Connection
Console.WriteLine("Connection Count = {0}", myModel.Connections.Count)
Dim CurConn As AFConnection
For Each CurConn In myModel.Connections
    Console.WriteLine("Name of Model = {0}", CurConn.Model.Name)
    Console.WriteLine("Source = {0}", CurConn.Source)
    Console.WriteLine("Source Port = {0}", CurConn.SourcePort)
    Console.WriteLine("Destination = {0}", CurConn.Destination)
    Console.WriteLine("Destination Port = {0}", CurConn.DestinationPort)
Next CurConn

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