AFElements.Add Method (String, AFElementTemplate)
- Last UpdatedNov 18, 2025
- 4 minute read
- PI System
- AF SDK 2024 R2
- Developer
Namespace: OSIsoft.AF.Asset
Assembly: OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 3.1.1.1182
Syntax
public AFElement Add( string name, AFElementTemplate template )
Public Function Add ( name As String, template As AFElementTemplate ) As AFElement Dim instance As AFElements Dim name As String Dim template As AFElementTemplate Dim returnValue As AFElement returnValue = instance.Add(name, template)
public: AFElement^ Add( String^ name, AFElementTemplate^ template )
member Add : name : string * template : AFElementTemplate -> AFElement
Parameters
- name
- Type: SystemString
The name for the new AFElement object. The name must be unique within the collection. If the name ends with an asterisk (*), then a unique name will be generated based on the supplied name. See the ValidateName(String, String) method for a description of what is valid when setting the name of the object. - template
- Type: OSIsoft.AF.AssetAFElementTemplate
The template that is to be used to create the new AFElement object or a type derived from AFElement (e.g. AFModel). Use one of the AFDatabase.AddTransfer Overload methods to add a transfer. If , then the element is created without a template and properties normally defined by the template will be defined by the element instead.
Return Value
Type: AFElementReturns the newly added AFElement object.
Remarks
The type of AFElement created by this method is determined by the template's InstanceType property. By default, the type will be AFElement, but could be any type derived from an AFElement (e.g. AFModel).
The new AFElement is added to this collection using the default AFReferenceType, Parent-Child. The default value of the Description property of the new element is the same as the description of the template; however, it can be changed by the user. All other properties are defined by the template and cannot be modified without changing the template.
Top-level elements of the database can be created by using this method on the AFDatabase.Elements collection. To create a new child element of another element, use one of the Add methods of the element's AFElement.Elements collection. To add an existing child element of another element, use one of the Add Overload methods the element's AFElement.Elements collection.
When an element is first added to a AFModel, the element is not connected to any other elements. Use one of the AFConnections.Add Overload methods to create a connection between two elements within the model.
When a reference is added to or removed from an element, the parent element is checked out in the client, but it is not actually checked out in the server. This allows elements to be added to or removed from the collection from multiple applications and then checked in without requiring a checkout lock on the parent element in the server. If any other change is made to the parent element, a full server checkout is performed. Calling ApplyChanges will also require a full server checkout to be performed before saving to the server.
| Only one reference between the AFDatabase and an AFElement is allowed and its AFReferenceStrength must be Strong. |