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

Getting User Defined properties

Andrey Shulyak
Participant
Hello all,
I have a problem with getting User Defined properties. This problem is associated with only one project so far, but I do not exclude that this is due to the fact that the elements in this project have a large number of properties. I get property in the standard way described in the documentation.
This is my code:

GS::Array<API_PropertyDefinition> definitions2;
 if (ACAPI_Element_GetPropertyDefinitions(elementapi->header.guid, API_PropertyDefinitionFilter_UserDefined, definitions2) == NoError)
		 {

   			GS::Array<API_Property> properties;
//next line very slow
			if (ACAPI_Element_GetPropertyValues(elementapi->header.guid, definitions, properties) == NoError)
			{
							UInt32 count = properties.GetSize();
							for (UInt32 j = 0; j < properties.GetSize(); j++)
							{
                                                                 .....
                                                                  ....
                                                        }
                          
                        }
                }

In total, the project has approximately 195 thousand elements (medium-sized project)
this is line works fast and getting an array of about 90 API_PropertyDefinition:

ACAPI_Element_GetPropertyDefinitions(elementapi->header.guid, API_PropertyDefinitionFilter_UserDefined, definitions2)

but the next line is executed relatively slowly (about a second for each Archicad element or each array API_PropertyDefinition (there are 195 thousand of them in the project), perhaps somewhere more somewhere less:

ACAPI_Element_GetPropertyValues(elementapi->header.guid, definitions, properties) 

And the whole project takes me about two days.
Most likely there is a way when I can get these properties faster, or somehow optimize the process of obtaining them. Please advise how it could be accelerated?

With Best Regards,
Andrey
1 REPLY 1
poco2013
Mentor
Unfortunately, I'm not a professional C++ coder, so really can't help, But:

Have you checked if you are running out of memory? Just leave open the task manager/performance and watch the memory & CPU loading? My experience is that the C++ API will load a few hundred elements with about 50 properties each in about a minute. Python would take about 5 minutes or less. There is no way 195 thousand elements should take two days. You did not note if you can filter the criteria as to elements or element type or limit the number properties returned. What do want to do with the data. Are you filtering it or off loading it. If so, there are better data analysis programs available such as Pandas, etc. Need more info.perhaps for others to help. You might also encode some timing logging around major blocks to see where the delays are? As in: a particular function or the accumulation of the whole process.

I suspect (only suspect) that the API is structured such that the code will iterate through all 195+ elements to find each property. Property structures are not part of the element's structure -- only linked to it. So double work in retrieving
Gerry

Windows 11 - Visual Studio 2022; ArchiCAD 27