cancel
Showing results for 
Search instead for 
Did you mean: 
EN
cancel
Showing results for 
Search instead for 
Did you mean: 
NMK195
Participant

How to Create a Property Using Add-ons

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:

 

NMK195_2-1747305435044.png

 

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()));

 

NMK195_1-1747305409639.png

 

3 Replies 3

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.

Ralph Wessel BArch
Central Innovation
NMK195
Participant

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));

}

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?

Ralph Wessel BArch
Central Innovation

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!