using OSIsoft.AF;
using OSIsoft.AF.Analysis;
using OSIsoft.AF.Search;
using OSIsoft.AF.Asset;
using System;
using System.Collections.Generic;
class Program
{
static void Main(string[] args)
{
// Connect to the PI System and Database
PISystems piSystems = new PISystems();
PISystem myPISystem = piSystems["PISystemName"];
AFDatabase myDatabase = myPISystem.Databases["AFDatabaseName"];
// Specify the element template name
string elementTemplateName = "myElementTemplate";
// Fetch the element template
AFElementTemplate elementTemplate = myDatabase.ElementTemplates[elementTemplateName];
if (elementTemplate == null)
{
Console.WriteLine("Element template not found.");
return;
}
// Specify the criteria to search for analyses
string query = $@"Template:'{elementTemplateName}' Name:'Calculate Value'";
// Create the AFAnalysisSearch object
AFAnalysisSearch analysisSearch = new AFAnalysisSearch(myDatabase, "AnalysisSearch", query);
// Execute the search and iterate through results
IEnumerable<AFAnalysis> analyses = analysisSearch.FindObjects();
foreach (AFAnalysis analysis in analyses)
{
Console.WriteLine($"Analysis Name: {analysis.Name}, Element: {analysis.Element.Name}");
}
}
}
lal_babu.shaik. I tried it, but template name takes the "analysis template name" i.e. "Calculate Value" in my case. It does not relate it with specific element template name. So, it will take all the analysis template named "Calculate value" in any element template.