2025-05-15
12:38 PM
- last edited on
2025-05-16
08:38 PM
by
Laszlo Nagy
Hi all,
I'm using Archicad API 22 and I want to create a group and a property for the entire model, as shown in the image below:
I found the example property_Test, but it only creates a property for the selected object, not for the entire model. I’ve tried modifying it, but haven’t been successful.
Can anyone help me with this?
API_PropertyGroup group;
ASSERT_NO_ERROR (PropertyTestHelpers::GetCommonExamplePropertyGroup (group));
API_PropertyDefinition definition;
definition = PropertyTestHelpers::CreateExampleIntPropertyDefinition (group);
// ACAPI_ElementList_AddProperty creates the property definition, if it doesn't exist yet
ASSERT_NO_ERROR (ACAPI_ElementList_AddProperty (definition, PropertyTestHelpers::GetSelectedElements()));
ASSERT (definition.guid != APINULLGuid);
// It works for already existing properties too
ASSERT_NO_ERROR (ACAPI_ElementList_AddProperty (definition, PropertyTestHelpers::GetSelectedElements()));
2025-05-16 12:18 PM
I think the code you want is in the Property_Text example. Take a look at the function SimpleTestPropertyDefinitions() in the file Property_Test.cpp, specifically where it calls ACAPI_Property_CreatePropertyDefinition to create a new property definition.
2025-05-21 07:18 AM
Hi!
Thank you for answering my question, but I still haven't been able to do it. Could you help me by adjusting the code below?
void CreateProperty(API_PropertyGroup group, GS::UniString str, GS::Array<API_Guid> listElement)
{
GS::Array<API_PropertyDefinition> defs;
if (ACAPI_Property_GetPropertyDefinitions(group.guid, defs) != NoError) {
DBPrintf("Cannot retrieve existing property definitions.\n");
return;
}
for (auto& d : defs) {
if (d.name == str) {
DBPrintf("Definition \"%ls\" already exists—no need to recreate.\n",
str.ToCStr());
return;
}
}
API_PropertyDefinition definition;
definition.guid = APINULLGuid;
definition.groupGuid = group.guid;
definition.name = str;
definition.description = str;
definition.collectionType = API_PropertySingleCollectionType;
definition.valueType = API_PropertyStringValueType;
definition.measureType = API_PropertyDefaultMeasureType;
definition.defaultValue.basicValue.singleVariant.variant.type = definition.valueType;
definition.defaultValue.basicValue.singleVariant.variant.uniStringValue = "";
ASSERT_NO_ERROR(ACAPI_ElementList_AddProperty(definition, listElement));
ASSERT(definition.guid != APINULLGuid);
// It works for already existing properties too
ASSERT_NO_ERROR(ACAPI_ElementList_AddProperty(definition, listElement));
}
2025-05-21 04:07 PM
The Archicad 22 API is a bit too old for me - I no longer have it installed. Are you able to work with anything more recent?