mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 22:50:21 +00:00
Fix #3502. New select similar feature.
This commit is contained in:
@@ -46,6 +46,7 @@ classes = (
|
|||||||
operator.SelectGlobalId,
|
operator.SelectGlobalId,
|
||||||
operator.SelectIfcClass,
|
operator.SelectIfcClass,
|
||||||
operator.SelectPset,
|
operator.SelectPset,
|
||||||
|
operator.SelectSimilar,
|
||||||
operator.ShowAllElements,
|
operator.ShowAllElements,
|
||||||
operator.ToggleFilterSelection,
|
operator.ToggleFilterSelection,
|
||||||
prop.BIMColour,
|
prop.BIMColour,
|
||||||
@@ -61,6 +62,7 @@ classes = (
|
|||||||
prop.IfcSelectorProperties,
|
prop.IfcSelectorProperties,
|
||||||
ui.BIM_PT_search,
|
ui.BIM_PT_search,
|
||||||
ui.BIM_PT_colour_by_property,
|
ui.BIM_PT_colour_by_property,
|
||||||
|
ui.BIM_PT_select_similar,
|
||||||
ui.BIM_UL_colourscheme,
|
ui.BIM_UL_colourscheme,
|
||||||
ui.BIM_UL_ifc_class_filter,
|
ui.BIM_UL_ifc_class_filter,
|
||||||
ui.BIM_UL_ifc_building_storey_filter,
|
ui.BIM_UL_ifc_building_storey_filter,
|
||||||
|
|||||||
@@ -18,12 +18,14 @@
|
|||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
import json
|
import json
|
||||||
|
import ifcopenshell.util.element
|
||||||
import blenderbim.tool as tool
|
import blenderbim.tool as tool
|
||||||
|
|
||||||
|
|
||||||
def refresh():
|
def refresh():
|
||||||
SearchData.is_loaded = False
|
SearchData.is_loaded = False
|
||||||
ColourByPropertyData.is_loaded = False
|
ColourByPropertyData.is_loaded = False
|
||||||
|
SelectSimilarData.is_loaded = False
|
||||||
|
|
||||||
|
|
||||||
class SearchData:
|
class SearchData:
|
||||||
@@ -76,3 +78,28 @@ class ColourByPropertyData:
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
return [(str(g.id()), g.Name or "Unnamed", "") for g in sorted(results, key=lambda x: x.Name or "Unnamed")]
|
return [(str(g.id()), g.Name or "Unnamed", "") for g in sorted(results, key=lambda x: x.Name or "Unnamed")]
|
||||||
|
|
||||||
|
|
||||||
|
class SelectSimilarData:
|
||||||
|
data = {}
|
||||||
|
is_loaded = False
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def load(cls):
|
||||||
|
cls.is_loaded = True
|
||||||
|
cls.data = {}
|
||||||
|
cls.data["element_key"] = cls.element_key()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def element_key(cls):
|
||||||
|
obj = bpy.context.active_object
|
||||||
|
if not obj:
|
||||||
|
return []
|
||||||
|
element = tool.Ifc.get_entity(obj)
|
||||||
|
if not element:
|
||||||
|
return []
|
||||||
|
keys = [a.name() for a in element.wrapped_data.declaration().as_entity().all_attributes()]
|
||||||
|
psets = ifcopenshell.util.element.get_psets(element, psets_only=True)
|
||||||
|
for pset, properties in psets.items():
|
||||||
|
keys.extend([f"{pset}.{name}" for name in properties.keys() if name != "id"])
|
||||||
|
return [(k, k, "") for k in keys]
|
||||||
|
|||||||
@@ -993,3 +993,21 @@ class AddToIfcGroup(Operator):
|
|||||||
bpy.ops.bim.edit_group()
|
bpy.ops.bim.edit_group()
|
||||||
bpy.ops.bim.disable_group_editing_ui()
|
bpy.ops.bim.disable_group_editing_ui()
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
class SelectSimilar(Operator, tool.Ifc.Operator):
|
||||||
|
bl_idname = "bim.select_similar"
|
||||||
|
bl_label = "Select Similar"
|
||||||
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
|
def _execute(self, context):
|
||||||
|
props = context.scene.BIMSearchProperties
|
||||||
|
obj = context.active_object
|
||||||
|
element = tool.Ifc.get_entity(obj)
|
||||||
|
value = ifcopenshell.util.selector.get_element_value(element, props.element_key)
|
||||||
|
for obj in context.visible_objects:
|
||||||
|
element = tool.Ifc.get_entity(obj)
|
||||||
|
if not element:
|
||||||
|
continue
|
||||||
|
if ifcopenshell.util.selector.get_element_value(element, props.element_key) == value:
|
||||||
|
obj.select_set(True)
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ from ifcopenshell.util.selector import Selector
|
|||||||
import blenderbim.tool as tool
|
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
|
from blenderbim.bim.module.search.data import SearchData, ColourByPropertyData, SelectSimilarData
|
||||||
from bpy.types import PropertyGroup
|
from bpy.types import PropertyGroup
|
||||||
from blenderbim.tool.ifc import Ifc
|
from blenderbim.tool.ifc import Ifc
|
||||||
from . import ui, prop, operator
|
from . import ui, prop, operator
|
||||||
@@ -38,6 +38,12 @@ from bpy.props import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_element_key(self, context):
|
||||||
|
if not SelectSimilarData.is_loaded:
|
||||||
|
SelectSimilarData.load()
|
||||||
|
return SelectSimilarData.data["element_key"]
|
||||||
|
|
||||||
|
|
||||||
def get_saved_searches(self, context):
|
def get_saved_searches(self, context):
|
||||||
if not SearchData.is_loaded:
|
if not SearchData.is_loaded:
|
||||||
SearchData.load()
|
SearchData.load()
|
||||||
@@ -110,6 +116,7 @@ class BIMColour(PropertyGroup):
|
|||||||
|
|
||||||
|
|
||||||
class BIMSearchProperties(PropertyGroup):
|
class BIMSearchProperties(PropertyGroup):
|
||||||
|
element_key: EnumProperty(items=get_element_key, name="Element Key")
|
||||||
filter_query: StringProperty(name="Filter Query")
|
filter_query: StringProperty(name="Filter Query")
|
||||||
filter_groups: CollectionProperty(type=BIMFilterGroup, name="Filter Groups")
|
filter_groups: CollectionProperty(type=BIMFilterGroup, name="Filter Groups")
|
||||||
facet: EnumProperty(
|
facet: EnumProperty(
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
from bpy.types import Panel
|
from bpy.types import Panel
|
||||||
from blenderbim.bim.module.search.data import SearchData, ColourByPropertyData
|
from blenderbim.bim.module.search.data import SearchData, ColourByPropertyData, SelectSimilarData
|
||||||
|
|
||||||
|
|
||||||
class BIM_PT_search(Panel):
|
class BIM_PT_search(Panel):
|
||||||
@@ -171,6 +171,30 @@ class BIM_PT_colour_by_property(Panel):
|
|||||||
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):
|
||||||
|
bl_label = "Select Similar"
|
||||||
|
bl_idname = "BIM_PT_select_similar"
|
||||||
|
bl_space_type = "PROPERTIES"
|
||||||
|
bl_region_type = "WINDOW"
|
||||||
|
bl_context = "scene"
|
||||||
|
bl_options = {"DEFAULT_CLOSED"}
|
||||||
|
bl_parent_id = "BIM_PT_tab_grouping_and_filtering"
|
||||||
|
|
||||||
|
def draw(self, context):
|
||||||
|
if not SelectSimilarData.is_loaded:
|
||||||
|
SelectSimilarData.load()
|
||||||
|
|
||||||
|
props = context.scene.BIMSearchProperties
|
||||||
|
|
||||||
|
if SelectSimilarData.data["element_key"]:
|
||||||
|
row = self.layout.row(align=True)
|
||||||
|
row.prop(props, "element_key", text="")
|
||||||
|
row.operator("bim.select_similar", text="", icon="RESTRICT_SELECT_OFF")
|
||||||
|
else:
|
||||||
|
row = self.layout.row()
|
||||||
|
row.label(text=f"No Active Element")
|
||||||
|
|
||||||
|
|
||||||
class BIM_UL_colourscheme(bpy.types.UIList):
|
class BIM_UL_colourscheme(bpy.types.UIList):
|
||||||
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
|
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
|
||||||
props = context.scene.BIMWorkScheduleProperties
|
props = context.scene.BIMWorkScheduleProperties
|
||||||
|
|||||||
@@ -888,8 +888,8 @@ class Drawing(blenderbim.core.tool.Drawing):
|
|||||||
try:
|
try:
|
||||||
shutil.move(src, dest)
|
shutil.move(src, dest)
|
||||||
except:
|
except:
|
||||||
# Perhaps the file is locked in Windows?
|
# Perhaps the file is locked in Windows?
|
||||||
shutil.copy(src, dest)
|
shutil.copy(src, dest)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def generate_drawing_name(cls, target_view, location_hint):
|
def generate_drawing_name(cls, target_view, location_hint):
|
||||||
@@ -1387,11 +1387,13 @@ class Drawing(blenderbim.core.tool.Drawing):
|
|||||||
root = tree.getroot()
|
root = tree.getroot()
|
||||||
rel_location = os.path.relpath(new_location, os.path.dirname(uri))
|
rel_location = os.path.relpath(new_location, os.path.dirname(uri))
|
||||||
|
|
||||||
for g in root.findall('.//{http://www.w3.org/2000/svg}g[@data-type="drawing"][@data-id="' + str(reference.id()) + '"]'):
|
for g in root.findall(
|
||||||
|
'.//{http://www.w3.org/2000/svg}g[@data-type="drawing"][@data-id="' + str(reference.id()) + '"]'
|
||||||
|
):
|
||||||
for foreground in g.findall('.//{http://www.w3.org/2000/svg}image[@data-type="foreground"]'):
|
for foreground in g.findall('.//{http://www.w3.org/2000/svg}image[@data-type="foreground"]'):
|
||||||
foreground.attrib['{http://www.w3.org/1999/xlink}href'] = rel_location
|
foreground.attrib["{http://www.w3.org/1999/xlink}href"] = rel_location
|
||||||
for background in g.findall('.//{http://www.w3.org/2000/svg}image[@data-type="background"]'):
|
for background in g.findall('.//{http://www.w3.org/2000/svg}image[@data-type="background"]'):
|
||||||
background.attrib['{http://www.w3.org/1999/xlink}href'] = rel_location[0:-4] + "-underlay.png"
|
background.attrib["{http://www.w3.org/1999/xlink}href"] = rel_location[0:-4] + "-underlay.png"
|
||||||
tree.write(uri, pretty_print=True, xml_declaration=True, encoding="utf-8")
|
tree.write(uri, pretty_print=True, xml_declaration=True, encoding="utf-8")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
Reference in New Issue
Block a user