3 Replies Latest reply on Dec 21, 2016 3:03 PM by VarbanVarbanov

    how to create af analysis with output attribute through af sdk

    VarbanVarbanov

      Hi, I'm trying to create AF Analysis with output attribute. I was trying various of combinations of the commented code below without success (analysis is allways created without output attribute reference). AF Sdk documentation does not explain anything different than already said in the method name:

       

        ana = new AFAnalysis(AFDatabase, an.Name);                
        ana.AnalysisRulePlugIn = _connection.PISystem.AnalysisRulePlugIns["PerformanceEquation"];
        ana.AnalysisRule.ConfigString = an.ExpressionString;             
        ana.Name = an.Name;
        element.Analyses.Add(ana);
                   
                          //var att = element.Attributes["TestA"];
                          //ana.AnalysisRule.GetOutputs().Add(att); // not that expect this to work
                          //ana.AnalysisRule.VariableMap.SetMapping("Variable1", new AFVariableMappingData(att));
                          //ana.AnalysisRule.MapVariable("Variable1", att);
                          //ana.AnalysisRule.MapVariable("Variable1", "TestA");
      
         AFDatabase.CheckIn();
      

       

      I would like to create the output attribute wothout writing tha analysis output to PI and to create the attribute with the analysis creation if possible, i.e I want to do the following:

       

      Output.png

       

      Please, tell me how to do this!

       

      Thank you in advance!

        • Re: how to create af analysis with output attribute through af sdk
          pmartin

          Hi Varban,

           

          It looks like you are quite close to the solution.  Did you create the output attribute before the code snippet you posted?

           

          AFAttribute att = referenceElement.Attributes.Add("Analysis Output");
          att.DataReferencePlugIn = server.DataReferencePlugIns["Analysis"];
          

           

          Aside from that, it looks like you have the rest of the components required.  For reference, this is what I used for mine:

           

          AFAnalysis analysis = new AFAnalysis(db, "Analysis1");
            analysis.Target = referenceElement;
          
            analysis.AnalysisRulePlugIn = server.AnalysisRulePlugIns["PerformanceEquation"];
            AFAnalysisRule arule = analysis.AnalysisRule;
            arule.ConfigString = "AnalysisOutput := 'CDT' * 2";
            arule.MapVariable("AnalysisOutput", "Analysis Output")
          
          • Re: how to create af analysis with output attribute through af sdk
            kfong

            Hi Varban,

             

            This is a good question.  Using AF SDK to specify configuration strings is less than ideal, and I highly recommend using PSE instead, as it supports Attribute name resolution and other helpful UI tools.  May I ask what your use case is for using AF SDK to create analyses rather than PSE?  If you need to create a lot of analyses, I recommend using Element Templates rather than a custom AF SDK solution.

            • Re: how to create af analysis with output attribute through af sdk
              VarbanVarbanov

              Thank you Martin, your suggertion worked! Yes, I was trying both creating attribute and without creating attribute (hoping to have the functionaliy from PSE, where you do not need to create the attribute, however it seems ok your way). But I was missing setting the attribute DataReferencePlugin. Keith, using PSE is not an option in my case. Does anybody know where can i find some AF Sdk examples for AF Analysis creation?