AnsweredAssumed Answered

Programmatic UOM

Question asked by mikespath on May 16, 2017
Latest reply on May 16, 2017 by mikespath


I'm wondering how to programatically set the UOM for an AFAttribute Template

Code below is what I'm using. The variable dst.Unit is just a string like "g/m", "sec.", etc..


string strFullParName = dst.ParamName;

                var atExists = db.ElementTemplates[dst.TemplateName].AttributeTemplates[strFullParName];

                if (atExists == null)


                    AFAttributeTemplate Myattributetemplate = myElemTemplate.AttributeTemplates.Add(strFullParName);

                    Myattributetemplate.DefaultUOM = MyPISystem.UOMDatabase.UOMs[dst.Unit];



                    Myattributetemplate.DataReferencePlugIn = AFDataReference.GetPIPointDataReference(MyPISystem);

                    Myattributetemplate.ConfigString = @"\\%Server%\%Element%.%Attribute%";



                    // setup limits for Attribute

                    AddLimitToAttribute(myElemTemplate, Myattributetemplate, dst.HiHi, LimitType.HIHI, dst.ParamName);


I can add one Attribute Template with % no problem

But when I try sec.

I get:

FAILS when I execute the line limitHiHi.Trait = AFAttributeTrait.LimitHiHi; below

if (myElemTemplate.AttributeTemplates[AFAttributeTrait.LimitHiHi.Abbreviation] == null)


                            AFAttributeTemplate limitHiHi = Myattributetemplate.AttributeTemplates.Add(AFAttributeTrait.LimitHiHi.Abbreviation);

                            limitHiHi.Trait = AFAttributeTrait.LimitHiHi;

                            limitHiHi.SetValue(dValue, limitHiHi.DefaultUOM);