1 Reply Latest reply on Apr 17, 2017 3:36 PM by pmartin

    Help with setting TimeTrue


      Can someone help me out with the differences in the code below? I'm trying to set the TimeTrue value in a Analysis Template Trigger. The picture below shows the result of the code with nothing in the True For column. I can set it fine in the Element itself (see commented code that works)

      Is there a step I'm missing for Templates?




                      // ****************** Start Create Analysis Template  *************************

                      AFAnalysisTemplate myATtemplate = elmTemplate.AnalysisTemplates[strAnalysisTemplateName];

                      if (myATtemplate == null)


                          myATtemplate = elmTemplate.AnalysisTemplates.Add(strAnalysisTemplateName);



                      // Define analysis rule plug in and build config string

                      myATtemplate.AnalysisRulePlugIn = MyPISystem.AnalysisRulePlugIns["EventFrame"];

                      myATtemplate.AnalysisRule.ConfigString = String.Format("EFTGUID={0};EFTNAME={1}", myEFTemplate.UniqueID, myEFTemplate.Name);


                      // Define plug in type and config string for child analysis rules

                      AFAnalysisRule triggerRule = myATtemplate.AnalysisRule.AnalysisRules.Add(MyPISystem.AnalysisRulePlugIns["PerformanceEquation"]);

                      triggerRule.ConfigString = "DO_HH:= 'DO' > 'DO|HiHi';";


                      AFAnalysisRule timeTrueRule = myATtemplate.AnalysisRule.AnalysisRules.Add(MyPISystem.AnalysisRulePlugIns["TimeTrue"]);

                      timeTrueRule.ConfigString = "TimeTrueValue=10";


                      /* reference code below works for TimeTrue

                  // Define analysis rule plug in and build config string 

                  efAnalysis.AnalysisRulePlugIn = MyPISystem.AnalysisRulePlugIns["EventFrame"];

                  efAnalysis.AnalysisRule.ConfigString = String.Format("EFTGUID={0};EFTNAME={1}", efTemplate.UniqueID, efTemplate.Name);



                  // Define plug in type and config string for child analysis rules 

                  AFAnalysisRule triggerRule = efAnalysis.AnalysisRule.AnalysisRules.Add(MyPISystem.AnalysisRulePlugIns["PerformanceEquation"]);

                  triggerRule.ConfigString = "StartTrigger:= 'Temperature' > 200;";

                  AFAnalysisRule timeTrueRule = efAnalysis.AnalysisRule.AnalysisRules.Add(MyPISystem.AnalysisRulePlugIns["TimeTrue"]);

                  timeTrueRule.ConfigString = "TimeTrueValue=56";



                  // Define natural time rule to trigger at any input 

                  efAnalysis.TimeRulePlugIn = MyPISystem.TimeRulePlugIns["Natural"];


                   //end of reference code   */


                      // Define natural time rule to trigger at any input

                      myATtemplate.TimeRulePlugIn = MyPISystem.TimeRulePlugIns["Natural"];




                      // ****************** End Create Analysis Template  *************************



        • Re: Help with setting TimeTrue

          Hi Mike,


          I have a function that should be able to add or modify a TimeTrue value for a simple, 1 Start Trigger,  EF Generation Analysis Template.  Hopefully this gives you a good starting point.


          AFAnalysisTemplate a = db.ElementTemplates["TrueFor"].AnalysisTemplates["A"];
          AFAnalysisRule ar = a.AnalysisRule.AnalysisRules["PerformanceEquation"];
          int newTimeTrue = 3600;
          if (!ar.ConfigString.Contains("@timetrue")) {
            //if no timetrue value exists for this analysis rule
            //insert timetrue after start triggers group
            string group = "@group(\"Start triggers\")";
            int index = ar.ConfigString.IndexOf(group) + group.Length;
            ar.ConfigString = ar.ConfigString.Insert(index, $" @timetrue(\"{newTimeTrue}\")");
          else {
            //if we are modifying an existing timetrue value
            //find and replace timetrue value with newTimeTrue value
            string newConfigString = Regex.Replace(ar.ConfigString, @"@timetrue.*", $"@timetrue(\"{newTimeTrue}\")\r");
            ar.ConfigString = newConfigString;
          2 of 2 people found this helpful