BIM Coordinator Program (INT) April 22, 2024

Find the next step in your career as a Graphisoft Certified BIM Coordinator!

Archicad C++ API
About Archicad add-on development using the C++ API.
SOLVED!

Change Value of singleEnumVariant

Anonymous
Not applicable
Hi all,

I'm trying to change individual properties in Archicad. This is no problem with text fields, but I fail with SingleEmu.

prop is my API_Property Object and chaning value with singlevariant works flawless just by changing uniStringValue
					GS::Array<API_SingleEnumerationVariant> listOfEnum = prop.definition.possibleEnumValues;
					for (UInt32 i = 0; i < listOfEnum.GetSize(); ++i) {
						API_SingleEnumerationVariant enumerator = listOfEnum;
						auto name_of_value = enumerator.displayVariant.uniStringValue.ToCStr();
						API_Guid guid_of_value = enumerator.keyVariant.guidValue;
						std::string test4 = name_of_value;
						if (test4 == "Teppich") {
							prop.value.singleEnumVariant = enumerator;
							
						}
			error = ACAPI_Element_SetProperty(Guid, prop);
My naive idea is to rite through the possible enumerators here and as soon as I have found the suitable one (here the entry "Teppich") and then attach this singleEnumVariant to my property I write back

But its not working and i dont get any error code either. Any Ideas?

Best Regards

Patrick
1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
Hi Patrick,

I think you forgot to set the isDefault flag in the property object to false. If it remains true, than it does not matter how do you change the object because finally the element will still have the default value of the property.
if (prop.definition.collectionType == API_PropertySingleChoiceEnumerationCollectionType &&
	prop.definition.valueType == API_PropertyStringValueType)
{
	for (const API_SingleEnumerationVariant& enumValue : prop.definition.possibleEnumValues) {
		if (enumValue.displayVariant.uniStringValue == "Teppich") {
			prop.value.singleEnumVariant = enumValue;

			prop.isDefault = false;
			error = ACAPI_Element_SetProperty(Guid, prop);
			break;
		}
	}
}
Regards,
Tibor

View solution in original post

2 REPLIES 2
Solution
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
Hi Patrick,

I think you forgot to set the isDefault flag in the property object to false. If it remains true, than it does not matter how do you change the object because finally the element will still have the default value of the property.
if (prop.definition.collectionType == API_PropertySingleChoiceEnumerationCollectionType &&
	prop.definition.valueType == API_PropertyStringValueType)
{
	for (const API_SingleEnumerationVariant& enumValue : prop.definition.possibleEnumValues) {
		if (enumValue.displayVariant.uniStringValue == "Teppich") {
			prop.value.singleEnumVariant = enumValue;

			prop.isDefault = false;
			error = ACAPI_Element_SetProperty(Guid, prop);
			break;
		}
	}
}
Regards,
Tibor
Anonymous
Not applicable
Thank you very much
Learn and get certified!