I was working on a backfilling script using powershell. I want analysis named 'Calculate Value' from a specific element template named 'myElementTemplate'. How can I get those analysis using 'AFAnalysisSearch' using af sdk ?

Parents
  • 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}");

        }

      }

    }

Reply
  • 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}");

        }

      }

    }

Children
No Data