Isolate/hide objects or classes based on selection
Hi,
I've started learning to code for BlenderBIM; the demo is great thanks.
As an exercise I made the following isolate/hide menu:
https://drive.google.com/file/d/1QZ3mLsyfp2UV2lDmYQIujaj7vbzAhHEV/view?usp=sharing
It's very similar to this discussion: https://community.osarch.org/discussion/767/
Have such tools already been implemented? Is it worth going on? (eg with shortcuts)
Let me know what you think :)
The code is :
import bpy
import blenderbim.tool as tool
visibility_changed = False
class IsolateSelectedObjects(bpy.types.Operator):
bl_idname = "bim.isolate_selected_objects"
bl_label = "Isolate Selected Objects"
bl_options = {"REGISTER", "UNDO"}
bl_description = "Isolate the selected objects"
ifc_class: bpy.props.StringProperty()
def execute(self, context):
selected_objects = context.selected_objects
for obj in bpy.data.objects:
global visibility_changed
if not visibility_changed:
obj["original_visibility"] = obj.hide_viewport
if obj not in selected_objects:
obj.hide_viewport = True
visibility_changed = True
return {'FINISHED'}
class HideSelectedObjects(bpy.types.Operator):
bl_idname = "bim.hide_selected_objects"
bl_label = "Hide Selected Objects"
bl_options = {"REGISTER", "UNDO"}
bl_description = "Hide the selected objects"
ifc_class: bpy.props.StringProperty()
def execute(self, context):
selected_objects = context.selected_objects
for obj in bpy.data.objects:
global visibility_changed
if not visibility_changed:
obj["original_visibility"] = obj.hide_viewport
if obj in selected_objects:
obj.hide_viewport = True
visibility_changed = True
return {'FINISHED'}
class IsolateSelectedClasses(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.isolate_selected_classes"
bl_label = "Isolate Selected Classes"
bl_options = {"REGISTER", "UNDO"}
bl_description = "Isolate the objects with the same class as one of the selected objects"
ifc_class: bpy.props.StringProperty()
def execute(self, context):
selected_objects = context.selected_objects
selected_classes = set()
for selected_obj in selected_objects:
element = tool.Ifc.get_entity(selected_obj)
selected_classes.add(element.is_a())
for obj in bpy.data.objects:
global visibility_changed
if not visibility_changed:
obj["original_visibility"] = obj.hide_viewport
if obj not in selected_objects:
element = tool.Ifc.get_entity(obj)
if element.is_a() not in selected_classes:
obj.hide_viewport = True
visibility_changed = True
return {'FINISHED'}
class HideSelectedClasses(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.hide_selected_classes"
bl_label = "Hide Selected Classes"
bl_options = {"REGISTER", "UNDO"}
bl_description = "Hide the objects with the same class as one of the selected objects"
ifc_class: bpy.props.StringProperty()
def execute(self, context):
selected_objects = context.selected_objects
selected_classes = set()
for selected_obj in selected_objects:
element = tool.Ifc.get_entity(selected_obj)
selected_classes.add(element.is_a())
for obj in bpy.data.objects:
global visibility_changed
if not visibility_changed:
obj["original_visibility"] = obj.hide_viewport
element = tool.Ifc.get_entity(obj)
if element.is_a() in selected_classes:
obj.hide_viewport = True
visibility_changed = True
return {'FINISHED'}
class RestoreOriginalVisibility(bpy.types.Operator):
bl_idname = "bim.restore_original_visibility"
bl_label = "Restore Original Visibility"
bl_options = {"REGISTER", "UNDO"}
bl_description = "Restore the original visibility state of objects"
def execute(self, context):
for obj in bpy.data.objects:
if "original_visibility" in obj:
obj.hide_viewport = obj["original_visibility"]
global visibility_changed
visibility_changed = False
return {'FINISHED'}
Comments
It's very similar how BlenderBIM spreadsheet hides and isolates from sorted IfcGuids from a spreadsheet.
https://github.com/C-Claus/blenderbim_spreadsheet/blob/master/operator.py#L396
What I think would be a really cool feature is if you manage to save the filters with the camera standpoint. I couldn't manage to do that.
The search filter panel has got quite a few ways to select elements, and there is also the select similar or filter selected panel which already exists. It sounds similar to what you've got there.
Thanks! What i had in mind was something similar to the HI HH IC HC HR hotkeys in Revit. I use a lot the "/" in Blender, which I found could be augmented in that way.
HI = \ or S-H
HH = H
IC = Select via outliner, search query, or click select class / select type in object information / select similar, then \ or S-H
HC = see above, then H
HR = A-H
Ok, thanks!