This article provides an example of how to set values for an enumeration type attribute that has a data dimension of Set using the API.


public void SetAttributeValue_OnAttributeWith_DataTypeEnumeration_And_DimensionSet()
        {
            // Set up attribute type with values BAT, ACC, IGN1, IGN2 and Start
            var attributeType = Broker.CreateAttributeType("ABCD", "Power", "", 
                SWAttributeDataType.Enumeration, SWAttributeDataDimension.Set, null, null);

            attributeType.Range = SWRange.RangeArrayToRange("BAT;ACC;IGN1;IGN2;Start");

            // Create item and add an attribute of type ABCD/Power
            var item = Broker.TopLibrary.CreateItem("I", "Test Item");
            item.AddAttribute(attributeType);
            IswAttribute attribute = item.GetAttributeOfType(attributeType);
            
            // Define a value that selects BAT and IGN1
            const string value = "<SET><VALUE>BAT</VALUE><VALUE>IGN1</VALUE></SET>";

            // Check that the value is valid according to the data type and assign it to the attribute
            if (attributeType.ValueIsValid(SWCompression.ZCompressStringToBytes(value)))
                attribute.SetValueAsXML(value);

            // Assert
            SWCompression.ZDecompressToString(attribute.ValueData).Should().Be(value);
        }

Example Attribute in swArchitect


Setting Values in swExplorer Client


The above value selection in XML format is: 


<SET><VALUE>BAT</VALUE><VALUE>IGN1</VALUE></SET>