AFElements.Add Method (String, AFElementTemplate, AFReferenceType, Object)
- Last UpdatedNov 18, 2025
- 5 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, AFReferenceType refType, Object effectiveDate )
Public Function Add ( name As String, template As AFElementTemplate, refType As AFReferenceType, effectiveDate As Object ) As AFElement Dim instance As AFElements Dim name As String Dim template As AFElementTemplate Dim refType As AFReferenceType Dim effectiveDate As Object Dim returnValue As AFElement returnValue = instance.Add(name, template, refType, effectiveDate)
public: AFElement^ Add( String^ name, AFElementTemplate^ template, AFReferenceType^ refType, Object^ effectiveDate )
member Add : name : string * template : AFElementTemplate * refType : AFReferenceType * effectiveDate : Object -> 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. Any template can be used as long as its InstanceType is AFElement 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. - refType
- Type: OSIsoft.AF.AssetAFReferenceType
The AFReferenceType specifies the hierarchical relationship between the newly created element and the element which own this collection of elements. The default reference type is the standard Parent-Child reference type. - effectiveDate
- Type: SystemObject
The effective date for the newly created object. The value may be an AFTime, DateTime, PITime, String, or numeric. A DateTime (or a DATE will be treated as UTC time if its Kind property is set to Unspecified. Because DATE values from COM or VB6 clients are marshalled as Unspecified, these client applications must convert to UTC prior to marshalling. An integer numeric represents the number of ticks (100-nanosecond intervals) since January 1, 0001. A floating point numeric represents the number of seconds since January 1, 1970 UTC. A String is interpreted as local time, unless it contains a time zone indicator such as a trailing "Z" or "GMT". Strings will be interpreted with the AFTime.Parse Overload methods so that relative formats with intervals ("*", "T+3h", etc.) are also supported. Relative time intervals are based on AFTime.Now.
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 specified AFReferenceType. A reference type with a Weak strength is not allowed because one weak reference is insufficient to keep an object alive. 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. |