We value your input! Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey
2023-04-27 10:37 AM - edited 2023-04-27 10:37 AM
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:
“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?
There must be a faster way. There is a faster way, right?
Any help or suggestions is highly welcomed! 🙂
2023-07-08 01:52 PM
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.
2023-07-09 11:58 AM - edited 2023-07-09 11:58 AM
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
2023-07-09 09:43 PM
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 =(
2023-07-10 08:38 AM
Glad to help! I think the main problem is, that there aren't many of us to begin with 😅
2023-07-10 09:25 AM
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)
2023-07-10 03:17 PM - edited 2023-07-10 04:05 PM
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! 🙂