BIM Coordinator Program (INT) April 22, 2024
Find the next step in your career as a Graphisoft Certified BIM Coordinator!
Archicad C++ API
About Archicad add-on development using the C++ API.

Fastest way to query Database for specific User defined Property?

Joel Buehler
Enthusiast

Hehey Archicad Chiefs!

 

I Want to query the database with user defined properties. I don’t know to which Elements the user applied the properties I have to look for. I only know that they are added to relevant elements like walls windows and stuff.

My questions for that topic are:

  1. What is the fastest way to query the Archicad Database through the API? The Documentation says explicit that one should not query the whole database, otherwise the database must be converted to api elements, and that seems to be slow. The Element-Overview page states:

“If you call the ACAPI_Element_Get function in a loop, Archicad is requested to convert all of the elements to API form, even if you do not need them. This algorithm can be very slow”

 

          But if I don’t know for which elements I’m looking for, what else can I do?

 

  1. Furthermore, I don’t see any possibility in the Add-On api to query specific Attributes. My understanding is, that I must get all elements, get all user defined properties from those elements and then I can look for my desired properties. That would look like something like that:

 

JoelBuehler_0-1682584603669.png

 

 

 

There must be a faster way. There is a faster way, right?

 

 

Any help or suggestions is highly welcomed! 🙂 

6 REPLIES 6
Joel Buehler
Enthusiast

a comment:

 

it makes no sense to retrieve all propertydefinitions of an elements and search for the desired property and the coresponding value. through property groups the amount of interesting ppdefintions can be drastically reduced. my shown example is working as intendend, but the performance in big models is not acceptable. my approach with a preselection of pp groups is way faster. 

Hi Joel,

 

If I understood your question correctly, I don't think you need to iterate through the elements at all.

If you already have the name of the correct property, you could first iterate through the properties separately.
Then with the property definition you can query the elements you want to.
For the last step you wouldn't even need ACAPI_Element_Get for that since the element guid is enough.

Something like this should be faster:

 

GS::Array<API_PropertyGroup> groups;
err = ACAPI_Property_GetPropertyGroups (groups);
if (err != NoError) { return; }

API_PropertyDefinition myPropertyToFind{};
for (const auto& group : groups) {
  GS::Array<API_PropertyDefinition> definitions;
  err = ACAPI_Property_GetPropertyDefinitions (group.guid, definitions);
  for (const auto& definition : definitions) {
    if (err != NoError) { return; }

    // You could filter out uneditable properties if wanted..
    if (!definition.canValueBeEditable) { continue; }

    // You could also filter out properties if they are not user defined.
    if (definition.definitionType != API_PropertyCustomDefinitionType) { continue; }

    if (definition.name == "MY SUPER TO SEARCH PROPERTY") {
      myPropertyToFind = definition;
      break;
    }
  }
}

API_Property propertyOut{};
ACAPI_Element_GetPropertyValue(elementGuid, myPropertyToFind, propertyOut);

 

 

By the way, also in your solution, I think you could just leave out the ACAPI_Element_Get call and use the element guid directly in ACAPI_Element_GetElementPropertyDefinitions.

Hope this helps,

Bernd

Bernd Schwarzenbacher - Archicad Add-On Developer - Get Add-Ons & Archicad Tips on my Website: Archi-XT.com

Thank you very much! glad to get finally some help. your help is very much appreciated since it seems that there are not to many developers left that are willing to help =(

 

 

 

Glad to help! I think the main problem is, that there aren't many of us to begin with 😅

Bernd Schwarzenbacher - Archicad Add-On Developer - Get Add-Ons & Archicad Tips on my Website: Archi-XT.com

yeah understanble since there isnt even an offical plugin store. =( (i like your plugins, specially the room cover plugin, they would fit perfectly in a store) 

Yeah an official store would be great. I think I've heard GS talk about ideas in that direction in some webinar. But it was quite a while ago and I couldn't find anything related on the roadmap. So I'm not counting on it.

Thanks for the kind words about my plugins! 🙂

Bernd Schwarzenbacher - Archicad Add-On Developer - Get Add-Ons & Archicad Tips on my Website: Archi-XT.com
Learn and get certified!