# How can i create a shortcut that will hide an object from viewport and render?

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.

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
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).

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

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.