Skip to content

Commit

Permalink
extends bim.select_type by selecting multiple types from a selection …
Browse files Browse the repository at this point in the history
…of objects.

Also when the type is selected and turned on, all other types are automatically turned off.
https://imgur.com/a/DQUF0ai
  • Loading branch information
theoryshaw committed May 3, 2024
1 parent 86cc2bf commit 080f325
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 17 deletions.
6 changes: 5 additions & 1 deletion src/blenderbim/blenderbim/bim/import_ifc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1498,7 +1498,11 @@ def add_project_to_scene(self):
# Occurs when reloading a project
pass
project_collection = bpy.context.view_layer.layer_collection.children[self.project["blender"].name]
project_collection.children[self.type_collection.name].hide_viewport = True
types_collection = project_collection.children[self.type_collection.name]
types_collection.hide_viewport = False
for obj in types_collection.collection.objects: #turn off all objects inside Types collection.
obj.hide_set(True)


def clean_mesh(self):
obj = None
Expand Down
1 change: 0 additions & 1 deletion src/blenderbim/blenderbim/bim/module/model/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ def draw(self, context):
op = row.operator("bim.rename_type", icon="GREASEPENCIL", text="")
op.element = relating_type["id"]
op = row.operator("bim.select_type", icon="OBJECT_DATA", text="")
op.relating_type = relating_type["id"]
op = row.operator("bim.duplicate_type", icon="DUPLICATE", text="")
op.element = relating_type["id"]
op = row.operator("bim.remove_type", icon="X", text="")
Expand Down
48 changes: 33 additions & 15 deletions src/blenderbim/blenderbim/bim/module/type/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,21 +146,39 @@ class SelectType(bpy.types.Operator):
relating_type: bpy.props.IntProperty()

def execute(self, context):
element = tool.Ifc.get().by_id(self.relating_type)
obj = tool.Ifc.get_object(element)
if obj:
try:
tool.Blender.select_and_activate_single_object(context, obj)
except:
self.report({"INFO"}, "Type object is hidden.")
# IfcTypeProducts are only used for annotations and not part of the model interface.
if element.is_a() != "IfcTypeProduct":
try:
context.scene.BIMModelProperties.ifc_class = element.is_a()
context.scene.BIMModelProperties.relating_type_id = str(self.relating_type)
except:
# Potentially our BIM Tool is filtered to a specific element.
pass
selected_objs = context.selected_objects
active_obj = context.active_object
selected_objs.append(active_obj) #update selected_objs so the active_obj is at the end of the list
last_relating_type_obj = None
types_collection = bpy.data.collections.get("Types")
for obj in types_collection.objects:
obj.hide_set(True)
for obj in selected_objs:
element = tool.Ifc.get_entity(obj)
relating_type = ifcopenshell.util.element.get_type(element)
relating_type_obj = tool.Ifc.get_object(relating_type)
obj.select_set(False)
if relating_type_obj:
if relating_type_obj.hide_get():
relating_type_obj.hide_set(False)
relating_type_obj.select_set(True)
last_relating_type_obj = relating_type_obj

context.view_layer.objects.active = last_relating_type_obj #make the active_obj's type the active object

# if relating_type_obj:
# try:
# tool.Blender.select_and_activate_single_object(context, relating_type_obj)
# except:
# self.report({"INFO"}, "Type object is hidden.")
# # IfcTypeProducts are only used for annotations and not part of the model interface.
# if element.is_a() != "IfcTypeProduct":
# try:
# context.scene.BIMModelProperties.ifc_class = element.is_a()
# context.scene.BIMModelProperties.relating_type_id = str(relating_type)
# except:
# # Potentially our BIM Tool is filtered to a specific element.
# pass
return {"FINISHED"}


Expand Down

1 comment on commit 080f325

@theoryshaw
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, this was meant to be a pull request.

I'm a little confused on what to do with this? 080f325#diff-6850b82c84f0a9fd5cf722733ae37ede701c2badeee1a4cfad757f7a0ab95cfdR169-R181

Please sign in to comment.