Lesson 5: Working with AF event frames
- Last UpdatedJan 15, 2026
- 2 minute read
- PI System
- AF SDK 3.2.0
- PI Server
After completing this lesson you will be able to perform the following tasks:
-
Use AF SDK to manage event frames
-
Create an event frame template
-
Create and work with event frames
Before you get started
You can find help in the following topics on the methods and data types used in this lesson:
Introduction to event frames
An Event Frame represents a time period defined by a start time and end time. Each Event Frame typically references one or more PI AF elements to associate the event with an asset. An Event Frame can also have a collection of child Event Frames, which represent child events that make up the larger event.
When creating AFEventFrame objects, the following properties should usually be set: StartTime, EndTime, and PrimaryReferencedElement.
AFEventFrame ef = new AFEventFrame(database, "*", eventFrameTemplate);
ef.SetStartTime(startTime);
ef.SetEndTime(endTime);
ef.PrimaryReferencedElement = meter;
When creating Event Frame templates in code, you might be surprised to discover there is no such object as AFEventFrameTemplate. Instead, an Event Frame template is a simply an AFElementTemplate with its InstanceType property set to typeof(AFEventFrame).
AFElementTemplate eventFrameTemplate =
database.ElementTemplates["Name of Template"];
if (eventFrameTemplate == null)
AFElementTemplate eventFrameTemplate =
database.ElementTemplates.Add("Name of Template");
eventFrameTemplate.InstanceType = typeof(AFEventFrame);
To find existing PI AF Event Frames, use the AFEventFrameSearch.FindEventFrames() method. You can search by name, start time, end time, duration, template, category, and a variety of other fields. Note that unlike elements, event frames cannot be accessed directly as a property under the AFDatabase object. For more information, see AFEventFrameSearch.FindEventFrames Method.
Note that AFEventFrameSearch is analogous to AFElementSearch from Lesson 2.
AFEventFrameSearch eventFrameSearch =
new AFEventFrameSearch(database, "EventFrame Captures", AFEventFrameSearchMode.ForwardFromStartTime,
startTime, queryString);
Note: Because Event Frames typically represent historical time ranges, attribute values of event frames typically do not change over time and can be cached to improve performance. In AF SDK, you can call the CaptureValues() method on an event frame instance to capture and save attribute values to the PI AF server for faster, subsequent retrieval. Updating the start or end time of the event frame will automatically recapture the values. For more information, see AFEventFrames.CaptureValues Method.
foreach (AFEventFrame item in eventFrameSearch.FindEventFrams())
{
item.CaptureValues();
}