users can now add selection to ifcgroup

This commit is contained in:
Vukas Pajic
2022-07-20 13:48:26 +02:00
parent ce6d4ea59a
commit df0c136b6c
4 changed files with 37 additions and 3 deletions
@@ -38,6 +38,7 @@ classes = (
operator.SaveSelectorQuery, operator.SaveSelectorQuery,
operator.OpenQueryLibrary, operator.OpenQueryLibrary,
operator.LoadQuery, operator.LoadQuery,
operator.AddToIfcGroup,
prop.BIMFilterClasses, prop.BIMFilterClasses,
prop.BIMFilterBuildingStoreys, prop.BIMFilterBuildingStoreys,
prop.BIMSearchProperties, prop.BIMSearchProperties,
@@ -20,6 +20,7 @@ import re
import bpy import bpy
import ifcopenshell import ifcopenshell
import ifcopenshell.util.element import ifcopenshell.util.element
from ifcopenshell.api.group.data import Data
from ifcopenshell.util.selector import Selector from ifcopenshell.util.selector import Selector
import blenderbim.tool as tool import blenderbim.tool as tool
from blenderbim.bim.ifc import IfcStore from blenderbim.bim.ifc import IfcStore
@@ -513,7 +514,7 @@ class FilterModelElements(Operator):
selection = self.add_filters(selection, query) selection = self.add_filters(selection, query)
elif query.selector == "GlobalId": elif query.selector == "GlobalId":
selection += f"#{query.global_id}" selection += f"#{query.value}"
elif query.selector == "IfcElementType": elif query.selector == "IfcElementType":
index = int(query.active_sub_option.split(":")[0]) index = int(query.active_sub_option.split(":")[0])
@@ -646,3 +647,29 @@ class LoadQuery(Operator):
ifc_selector = context.scene.IfcSelectorProperties ifc_selector = context.scene.IfcSelectorProperties
ifc_selector.selector_query_syntax = ifc_selector.query_library[self.index].query ifc_selector.selector_query_syntax = ifc_selector.query_library[self.index].query
return {"FINISHED"} return {"FINISHED"}
class AddToIfcGroup(Operator):
bl_idname = "bim.add_to_ifc_group"
bl_label = "Add to IFC Group"
group_name: StringProperty(name="Group Name")
def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self, width=400)
def draw(self, context):
layout = self.layout
layout.prop(self, "group_name")
def execute(self, context):
self.file = IfcStore.get_file()
ifc_selector = context.scene.IfcSelectorProperties
selector_query_syntax = ifc_selector.selector_query_syntax
group = ifcopenshell.api.run("group.add_group", self.file, **{"Name": self.group_name})
objects = Selector.parse(self.file, selector_query_syntax)
for obj in objects:
ifcopenshell.api.run("group.assign_group", self.file, **{"product": obj, "group": group})
Data.load(IfcStore.get_file())
return {"FINISHED"}
@@ -155,6 +155,10 @@ class IfcSelectorUI:
row.operator("bim.save_selector_query", text="Save Query") row.operator("bim.save_selector_query", text="Save Query")
row.operator("bim.open_query_library", text="Load Query") row.operator("bim.open_query_library", text="Load Query")
row = layout.row(align=True)
row.alignment = "CENTER"
row.operator("bim.add_to_ifc_group", text="Add to IFC Group")
def draw_query_group_ui(self, ifc_selector, layout): def draw_query_group_ui(self, ifc_selector, layout):
for index, group in enumerate(ifc_selector.groups): for index, group in enumerate(ifc_selector.groups):
row = layout.row() row = layout.row()
@@ -23,7 +23,9 @@ import ifcopenshell.api
class Usecase: class Usecase:
def __init__(self, file, **settings): def __init__(self, file, **settings):
self.file = file self.file = file
self.settings = {} self.settings = {
"Name": "Unnamed"
}
for key, value in settings.items(): for key, value in settings.items():
self.settings[key] = value self.settings[key] = value
@@ -33,6 +35,6 @@ class Usecase:
**{ **{
"GlobalId": ifcopenshell.guid.new(), "GlobalId": ifcopenshell.guid.new(),
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", self.file), "OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", self.file),
"Name": "Unnamed", "Name": self.settings["Name"],
} }
) )