Now support custom attributes in IfcSelector #2649

This commit is contained in:
Vukas Pajic
2023-01-16 08:58:14 +01:00
parent 6b63b5aae7
commit 8110951987
3 changed files with 10 additions and 7 deletions
@@ -527,7 +527,11 @@ class FilterModelElements(Operator):
if f.selector == "IfcPropertySet":
selection += f'{f.active_option.split(": ")[1]}.{f.active_sub_option.split(": ")[1]} {"!" if f.negation else ""}{comparison_operator} "{f.value}"'
elif f.selector == "Attribute":
selection += f'{f.attribute} {"!" if f.negation else ""}{comparison_operator} "{f.value}"'
# we're using the prop_search functionality in blender which returns the index of the option. Sometimes the user can override this and enter a value that doesn't exist in the list. In this case there is no index and we need to handle it. @vulevukusej
pattern = re.compile(r'^[0-9]+:')
match = pattern.search(f.active_option)
selection += f'{f.active_option.split(": ")[1] if match else f.active_option} {"!" if f.negation else ""}{comparison_operator} "{f.value}"'
selection += "]"
return selection
@@ -130,6 +130,10 @@ def load_selection_options(self, context):
elif self.selector == "IfcPropertySet":
psets = Selector.parse(ifc, ".IfcPropertySet")
options = set([o.Name for o in psets])
elif self.selector == "Attribute":
attributes = ["GlobalId", "Name", "Description", "ObjectType", "Tag", "PredefinedType"]
for a in attributes:
options.append((a, a, ""))
elif load_option == "sub_options":
if self.selector in ["IfcSpatialElement", "IfcElementType"]:
@@ -208,11 +212,6 @@ class SearchQueryFilter(PropertyGroup, IfcSelector):
update=load_selection_options,
default="-",
)
attribute: EnumProperty(
items=[(i, i, i) for i in ["GlobalId", "Name", "Description", "ObjectType", "Tag", "PredefinedType"]],
name="Filter selection by",
update=load_selection_options,
)
class SearchQuery(PropertyGroup, IfcSelector):
@@ -224,7 +224,7 @@ class IfcSelectorUI:
row.prop(f, "selector", text="")
if f.selector == "Attribute":
row.prop(f, "attribute", text="")
row.prop_search(f, "active_option", f, "options", text="", results_are_suggestions=True)
row.prop(
f,
"negation",