I'm developing an add-on that sets classification of items. It iterates an array with element GUIDS and classification GIUDS and sets the element to the matching classification. I use the ACAPI_Element_AddClassificationItem function and it works, but it is lightyears slower than the "seemingly" same function in the Python API.
Has anyone exeperienced something similar? Here's a piece of code:
GS::Array<GS::Pair<API_Guid, API_Guid>> finalElemClassification;
for (unsigned int i = 0; i < elementList.GetSize(); i++)
for (auto j : finalElemClassification)
err = ACAPI_Element_AddClassificationItem(j.first, j.second);
Up until the last loop there's no problem with speed and performance.
Meanwhile doing the same thing with the python API and using the SetClassificationsOfElements function to set the classification of elements is way faster.
I'm testing this on a project with approximately 10000 elements.
I also noticed that the python script uses all CPU threads while the C++ add-on uses only one...
Has anyone any idea how I could improve the C++ code to reach the same speed? What am I doing wrong?
My guess is that the ACAPI_Element_AddClassificationItem function opens a command scope internally, so it creates thousands of undo steps. I'd try to wrap the entire loop with a ACAPI_CallUndoableCommand call and see if that helps.