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

ACAPI_Element_AddClassificationItem function - /C++ vs Python/

SzokeFerenc
Booster

Hello Everybody!

 

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++)
{
    if (classifications.ContainsKey(layerPrefixArray[i]))
    {
        finalElemClassification.Push(GS::Pair<API_Guid, API_Guid>(elementList[i], 
        classifications[layerPrefixArray[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?

1 ACCEPTED SOLUTION
2 REPLIES 2
Solution
kovacsv
Booster

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.

SzokeFerenc
Booster

Thank you so much for the quick answer! I tried what you suggested and it works!

It was a very good lesson for me! Thank you!

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!