AFValue.Convert Method (UOMGroup)
- Last UpdatedJan 12, 2026
- 3 minute read
- PI System
- AF SDK 3.2.0
- Developer
Namespace: OSIsoft.AF.Asset
Assembly: OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 3.2.0.7
Syntax
public AFValue Convert( UOMGroup uomGroup = null )
Public Function Convert ( Optional uomGroup As UOMGroup = Nothing ) As AFValue Dim instance As AFValue Dim uomGroup As UOMGroup Dim returnValue As AFValue returnValue = instance.Convert(uomGroup)
public: AFValue^ Convert( UOMGroup^ uomGroup = nullptr )
member Convert : ?uomGroup : UOMGroup (* Defaults: let _uomGroup = defaultArg uomGroup null *) -> AFValue
Parameters
- uomGroup (Optional)
- Type: OSIsoft.AF.UnitsOfMeasureUOMGroup
The UOMGroup to use for the desired mapped UOM to be used for converting the Value. If this parameter is , then the UOMGroup specified by the DisplayUOMGroup will be used.
Return Value
Type: AFValueReturns the existing AFValue if the current UOM is not defined or a mapping does not exist for the current UOM. Otherwise, returns a new AFValue in the mapped UOM specified by the uomGroup.
Remarks
If the current UOM for the value is not set or a mapping does not exist for the current UOM in the uomGroup, then no conversion takes place and the current value will be returned.
If the Value is an Array, then each item in the array will be converted using the mapping defined by the specified uomGroup.
Examples
// This example will create a UOM Group with mappings, display its information, // and then perform some conversions. // Get the Database PISystems myPISystems = new PISystems(); UOMDatabase myDB = myPISystems.DefaultPISystem.UOMDatabase; // Create a UOM Group UOMGroup MyCustomGroup = myDB.UOMGroups.Add("MyCustomUOMGroup*"); MyCustomGroup.Description = "Custom UOM Group for Length"; // Add mappings to group MyCustomGroup.Mappings[myDB.UOMs["ft"]] = myDB.UOMs["m"]; MyCustomGroup.Mappings[myDB.UOMs["in"]] = myDB.UOMs["cm"]; MyCustomGroup.Mappings[myDB.UOMs["nmi"]] = myDB.UOMs["km"]; MyCustomGroup.Mappings[myDB.UOMs["mi"]] = myDB.UOMs["km"]; MyCustomGroup.Mappings[myDB.UOMs["mm"]] = myDB.UOMs["cm"]; MyCustomGroup.Mappings[myDB.UOMs["sxi"]] = myDB.UOMs["cm"]; MyCustomGroup.Mappings[myDB.UOMs["yd"]] = myDB.UOMs["m"]; myDB.CheckIn(); // Display the UOM Groups foreach (UOMGroup group in myDB.UOMGroups) { Console.WriteLine("Name of UOM Group = {0}", group.Name); Console.WriteLine("Description = {0}", group.Description); Console.WriteLine("Mappings:"); foreach (KeyValuePair<UOM, UOM> item in group.Mappings) { Console.WriteLine(" {0} ==> {1}", item.Key, item.Value); } } // Perform some conversions AFValue origAFValue = new AFValue(55.3, AFTime.Now, myDB.UOMs["mi"]); double mappedValue = MyCustomGroup.Convert(100.0, myDB.UOMs["yd"]); Console.WriteLine("Convert 100.0 ft ==> {0}", mappedValue); AFValue mappedAFValue = origAFValue.Convert(MyCustomGroup); Console.WriteLine("Convert {0} {1} ==> {2} {3}", origAFValue.Value, origAFValue.UOM, mappedAFValue.Value, mappedAFValue.UOM); // Display attribute value using Display UOM myDB.DisplayUOMGroup = MyCustomGroup; origAFValue = MyAttr.GetValue(); mappedAFValue = MyAttr.GetValue(MyAttr.DisplayUOM); Console.WriteLine("GetValue {0} {1} ==> {2} {3}", origAFValue.Value, origAFValue.UOM, mappedAFValue.Value, mappedAFValue.UOM);