UOMs.AddFormula Method
- Last UpdatedNov 18, 2025
- 4 minute read
- PI System
- AF SDK 2024 R2
- Developer
Namespace: OSIsoft.AF.UnitsOfMeasure
Assembly: OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 3.1.1.1182
Syntax
public UOM AddFormula( string name, string abbreviation, UOM refUOM, string fromFormula, string toFormula )
Public Function AddFormula ( name As String, abbreviation As String, refUOM As UOM, fromFormula As String, toFormula As String ) As UOM Dim instance As UOMs Dim name As String Dim abbreviation As String Dim refUOM As UOM Dim fromFormula As String Dim toFormula As String Dim returnValue As UOM returnValue = instance.AddFormula(name, abbreviation, refUOM, fromFormula, toFormula)
public: UOM^ AddFormula( String^ name, String^ abbreviation, UOM^ refUOM, String^ fromFormula, String^ toFormula )
member AddFormula : name : string * abbreviation : string * refUOM : UOM * fromFormula : string * toFormula : string -> UOM
Parameters
- name
- Type: SystemString
The name for the new object. The name must be unique within the collection. If the name ends with an asterisk (*), then a unique name will be generated based on the supplied name. See the ValidateName(String, String) method for a description of what is valid when setting the name of the object. - abbreviation
- Type: SystemString
The abbreviation for the new UOM. The abbreviation must be unique within the collection or the same as the name parameter. If not specified (empty or ), the abbreviation defaults to the same as the name. - refUOM
- Type: OSIsoft.AF.UnitsOfMeasureUOM
The reference unit of measure for this UOM conversion. This UOM must belong to the same UOM class and not create any circular references. - fromFormula
- Type: SystemString
The formula to apply to the reference UOM to obtain this UOM. The formula must contain a reference to the refUOM by abbreviation. See UOM.RefFormulaFrom for more information. - toFormula
- Type: SystemString
The formula to apply to this UOM to obtain the reference UOM. The formula must contain a reference to the abbreviation parameter. See UOM.RefFormulaTo for more information.
Return Value
Type: UOMReturns the newly created object that was added.
Remarks
This method creates a UOM using the specified conversion formulas. When possible, use the standard factor and offset conversions instead of formula-based conversions. You need to enter conversion formulas for both converting from and to the reference unit. These formulas must be reciprocals.
The formulas are written in terms of the UOM abbreviation (see the example below), and adhere to C# evaluation rules. If either of the abbreviations are not valid C# variable names, you must enclose them in brackets. Since C# is used to evaluate the expression, you can invoke standard .NET static methods such as Math.Log10 within the expression.
Examples
// This example demonstrates how to create UOMs using the UOMs.AddFormula method. // Get the Database PISystems myPISystems = new PISystems(); UOMDatabase myDB = myPISystems.DefaultPISystem.UOMDatabase; // Create the UOM Class UOMClass SGUOMClass = myDB.UOMClasses.Add("My Specific Gravity", "MySG", "MySG"); // Create the UOM UOM API = myDB.UOMs.AddFormula("My API Gravity", "MyAPI", myDB.UOMs["MySG"], "141.5/MySG - 131.5", "141.5/(MyAPI+131.5)");
' This example demonstrates how to create UOMs using the UOMs.AddFormula method. ' Get the Database Dim myPISystems As New PISystems Dim myDB As UOMDatabase = myPISystems.DefaultPISystem.UOMDatabase ' Create the UOM Class Dim SGUOMClass As UOMClass = myDB.UOMClasses.Add("My Specific Gravity", "MySG", "MySG") ' Create the UOM Dim API As UOM = myDB.UOMs.AddFormula("My API Gravity", "MyAPI", myDB.UOMs("MySG"), "141.5/MySG - 131.5", "141.5/(MyAPI+131.5)")
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.