You can now select coloured objects in a colourscheme.

This commit is contained in:
Dion Moult
2023-10-06 16:51:50 +11:00
parent 78c748df5d
commit d092fd45ba
4 changed files with 39 additions and 3 deletions
@@ -40,6 +40,7 @@ classes = (
operator.SaveSearch, operator.SaveSearch,
operator.SaveSelectorQuery, operator.SaveSelectorQuery,
operator.Search, operator.Search,
operator.SelectByProperty,
operator.SelectFilterElements, operator.SelectFilterElements,
operator.SelectGlobalId, operator.SelectGlobalId,
operator.SelectIfcClass, operator.SelectIfcClass,
@@ -333,6 +333,36 @@ class ColourByProperty(Operator):
data["area"].spaces[0].shading.color_type = "OBJECT" data["area"].spaces[0].shading.color_type = "OBJECT"
class SelectByProperty(Operator):
bl_idname = "bim.select_by_property"
bl_label = "Select by Property"
bl_options = {"REGISTER", "UNDO"}
@classmethod
def poll(cls, context):
props = context.scene.BIMSearchProperties
return props.active_colourscheme_index < len(props.colourscheme)
def execute(self, context):
props = context.scene.BIMSearchProperties
query = props.colourscheme_query
if not query:
self.report({"ERROR"}, "No Query Provided")
return {"CANCELLED"}
active_value = props.colourscheme[props.active_colourscheme_index].name
for obj in context.visible_objects:
element = tool.Ifc.get_entity(obj)
if not element:
continue
value = str(ifcopenshell.util.selector.get_element_value(element, query))
if value == active_value:
obj.select_set(True)
return {"FINISHED"}
class SaveColourscheme(Operator, tool.Ifc.Operator): class SaveColourscheme(Operator, tool.Ifc.Operator):
bl_idname = "bim.save_colourscheme" bl_idname = "bim.save_colourscheme"
bl_label = "Save Colourscheme" bl_label = "Save Colourscheme"
@@ -356,7 +386,9 @@ class SaveColourscheme(Operator, tool.Ifc.Operator):
description["colourscheme_query"] = query description["colourscheme_query"] = query
group.Description = json.dumps(description) group.Description = json.dumps(description)
else: else:
description = json.dumps({"type": "BBIM_Search", "colourscheme": coulour_scheme,"colourscheme_query": query}) description = json.dumps(
{"type": "BBIM_Search", "colourscheme": coulour_scheme, "colourscheme_query": query}
)
group = ifcopenshell.api.run("group.add_group", tool.Ifc.get(), Name=self.name, Description=description) group = ifcopenshell.api.run("group.add_group", tool.Ifc.get(), Name=self.name, Description=description)
def invoke(self, context, event): def invoke(self, context, event):
@@ -17,9 +17,9 @@
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>. # along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import bpy import bpy
import blenderbim.tool as tool
from ifcopenshell import util from ifcopenshell import util
from ifcopenshell.util.selector import Selector from ifcopenshell.util.selector import Selector
import blenderbim.tool as tool
from blenderbim.bim.prop import ObjProperty, StrProperty from blenderbim.bim.prop import ObjProperty, StrProperty
from blenderbim.bim.ifc import IfcStore from blenderbim.bim.ifc import IfcStore
from blenderbim.bim.module.search.data import SearchData, ColourByPropertyData, SelectSimilarData from blenderbim.bim.module.search.data import SearchData, ColourByPropertyData, SelectSimilarData
@@ -87,9 +87,12 @@ class BIM_PT_colour_by_property(Panel):
row = self.layout.row(align=True) row = self.layout.row(align=True)
row.operator("bim.colour_by_property", icon="BRUSH_DATA") row.operator("bim.colour_by_property", icon="BRUSH_DATA")
row.operator("bim.reset_object_colours") row.operator("bim.reset_object_colours")
row.operator("bim.select_by_property", icon="RESTRICT_SELECT_OFF", text="")
if len(props.colourscheme): if len(props.colourscheme):
self.layout.template_list("BIM_UL_colourscheme", "", props, "colourscheme", props, "active_colourscheme_index") self.layout.template_list(
"BIM_UL_colourscheme", "", props, "colourscheme", props, "active_colourscheme_index"
)
class BIM_PT_select_similar(Panel): class BIM_PT_select_similar(Panel):