3
$\begingroup$

Apparently ctrl+h used to do that but this is mapped to hide collection since 2.8. Basically when i press h to hide an object, i want it to hide from render as well so that i don't have to do it in the outliner. Please help, this is annoying me more than it should.

$\endgroup$

1 Answer 1

2
$\begingroup$

You are right, Ctrl+H is now used for Collections.

So i wrote a little add-on that does what you asked for, as it's not possible to set the H key to do more then one function without.

Here the code, you can just copy, paste it in a text editor (blender has one too) and save it as "hide-unhide.py" and afterwards install it in Blender from the "Preferences" "Add-on" section.

bl_info = {
    "name": "Hide selected/hide not selected and unhide from View&Render",
    "author": "Xylvier",
    "version": (1, 0),
    "blender": (2, 80, 0),
    "location": "",
    "description": "Hides selected/not selected and unhides objects from view and render at the same time",
    "warning": "",
    "wiki_url": "",
    "category": "operator",
}

import bpy

class HideselectedSet(bpy.types.Operator):
    """Hides selected objects from render&viewport"""
    bl_idname = "object.hide_set"
    bl_label = "Hide selected Objects from render&viewport"

    @classmethod
    def poll(cls, context):
        return context.selected_objects is not None

    def execute(self, context):
        for ob in context.selected_objects:
            ob.hide_viewport = True
            ob.hide_render = True
        return {'FINISHED'}

class HidenotselectedSet(bpy.types.Operator):
    """Hides not selected objects from render&viewport"""
    bl_idname = "object.invhide_set"
    bl_label = "Hide not selected Objects from render&viewport"

    @classmethod
    def poll(cls, context):
        return context.selected_objects is not None

    def execute(self, context):
        for obj in bpy.data.objects:
            if obj not in context.selected_objects:
                obj.hide_viewport = True
                obj.hide_render = True
        return {'FINISHED'}

class UnhideSet(bpy.types.Operator):
    """Unhides selected objects from render&viewport"""
    bl_idname = "object.unhide_set"
    bl_label = "Unhide Objects from render&viewport"

    def execute(self, context):
        bpy.ops.object.hide_render_clear_all()
        for obj in bpy.data.objects:
            obj.hide_viewport = False
            obj.hide_render = False
        return {'FINISHED'}

def register():
    bpy.utils.register_class(HideselectedSet)
    bpy.utils.register_class(UnhideSet)
    bpy.utils.register_class(HidenotselectedSet)

def unregister():
    bpy.utils.unregister_class(HideselectedSet)
    bpy.utils.unregister_class(UnhideSet)
    bpy.utils.unregister_class(HidenotselectedSet)

if __name__ == "__main__":
    register()

That said, you will have to adjust 3 keybindings in the keymap.

Go in the preferences, under keymap and open 3D View > Object Mode > Object Mode(Global).

should look like this

Scroll down to find these 3: "Show Hidden Objects" "Hide Objects" "Hide Objects"

new keymappings needed

Deselect them, no need to delete, like in the picture, after deselecting the 3 keymappings, we need to create 3 new ones to keep the functionality:

  1. object.unhide_set for Alt+H
  2. object.hide_set for H
  3. object.invhide_set for Shift+H

Those keybindings will work only if the add-on is installed and activated though, as the operators called by the keymappings are the 3 operators registered in the add-on. With that you have the same functionality as before, just that it affects viewport and render. BUT read below.

Word of caution: While this works for objects, as was asked, be aware that the deeper functionality of blenders base hide and unhide as well as the inverse hide work for everything. Vertices, edges and faces and uv meshes. To incorporate all that as well would be a bit bigger task. So i mentioned that it's better to not delete the default keymaps, but instead deselect them.

$\endgroup$
3
  • $\begingroup$ Hello Xylvier, from the day I have find your solution for disabling object from viewport and render in the same time, I have never restore the Blender original shortcuts. There's a small problem we have now with and I hope you can edit your script to resolve this issue. When you hide imported asset using shortcut and unhide it again, it just enable asset in vieport but it stay hidden in render. You can check this if you use Ctrl+A on selected asset and "Make instances Real"...it will unpack the asset and every object in it is hidden from render... Would you be so kind to do that? TNX $\endgroup$
    – Igor
    Commented Jan 23, 2023 at 23:04
  • $\begingroup$ Updated the missing unhide from render. Was my oversight to have missed that, sorry. $\endgroup$
    – Xylvier
    Commented Jan 24, 2023 at 9:43
  • $\begingroup$ Great! It works perfectly...thanks a lot!!! $\endgroup$
    – Igor
    Commented Jan 24, 2023 at 17:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .