# Render region and render with 1 keystroke?

I was looking into this: https://github.com/CenekStrichel/CendaTools/wiki/Render-Tools And there´s 1 key assignment to do the render region.

Basically you have: step 1: If user presses "(key)", invoke view3d.render_border command step 2: view3d.toggle_renderer step 3: Render area gets represented. step 4: IF a render area exist, and user presses "(key)" THEN view3d.clear_render_border

How could an .addon be created bindig all those commands and IF statement to a single keystroke?

Could this code get us started?

import bpy

class QuickRenderRegion(bpy.types.Operator):
"""Tooltip"""
bl_idname = "view3d.toggle_render"
bl_label = "QuickRenderRegion"
bl_options = {'REGISTER', 'UNDO'}

@classmethod
def execute(self, context):
bpy.ops.view3d.render_border()
bpy.ops.view3d.toggle_render
#return {'FINISHED'}

def register():
bpy.utils.register_class(QuickRenderRegion)

def unregister():
bpy.utils.unregister_class(QuickRenderRegion)

if __name__ == "__main__":
register()

• Modal operator. Have a look into Templates > Python > Operator Modal. However that's cumbersome in this case. Out of curiosity: why you can't just use Ctrl+B? – p2or Jun 18 '18 at 9:48
• ctrl+b, shift+z, wait for render, shift+z, ctrl+alt+b <---- Outrageous combo! Ultra finish. (I think you get me). Keybinding it to 1 key: genius. – Pierre Schiller Jun 18 '18 at 17:17
• Simple example on how to bind an operaor to any shortcut. I think you get the idea, copy the operator and just replace the name of the class when calling keymap_items.new() and you are literally done. But notice that the operator you've linked to, actually needs a cleanup before using it in a production: there are bad references, bpy is imported multiple times etc... – p2or Jun 19 '18 at 13:48
• Actually it would be necessary to anchor 3 commands to the same keybind: 1-that starts the drawing rectangle area, 2 shifts to render, 3 if the same key is pressed again and there is a render preview area, then clear the area first and go into rectangle draw area again unless "ESC" is pressed and session will cancel (toggle back to regular selection mode). – Pierre Schiller Jun 21 '18 at 16:00
• @PierreSchiller you should make your solution into an answer to close this question. I don't think there is any better solution. – HenrikD Mar 5 at 16:35

I took p2or link and modified a little. After running the script, shortcut key is Shift + Q. def register() part has type = "Q" and shift = True alt = False and ctrl = False.

bl_info = {
"name": "Toggle Simplify",
"description": "Toggle Simplify",
"author": "poor",
"version": (0, 0, 2),
"blender": (2, 79, 6),
"location": "3D View",
"category": "3D View"
}

import bpy

# operator
class ToggleSimplify(bpy.types.Operator):
"""Tooltip"""
bl_idname = "view3d.toggle_simplify"
bl_label = "Toggle Simplify"
bl_options = {'REGISTER'}

border = bpy.props.BoolProperty(default=False)

def execute(self, context):

if bpy.context.area.spaces.active.use_render_border:
bpy.context.area.spaces.active.use_render_border = False
self.border = False
bpy.ops.view3d.toggle_render()
else:
bpy.ops.view3d.render_border("INVOKE_DEFAULT")

return {'RUNNING_MODAL'}

def modal(self, context, event):

if not self.border and context.area.spaces.active.use_render_border:
bpy.ops.view3d.toggle_render()
self.border = True
return {'FINISHED'}
return {'PASS_THROUGH'}

# register
def register():
bpy.utils.register_class(ToggleSimplify)

# handle the keymap
wm = bpy.context.window_manager
if kc:
kmi = km.keymap_items.new(ToggleSimplify.bl_idname, type='Q', value='PRESS', shift=True, alt=False, ctrl=False)

# unregister
def unregister():
km.keymap_items.remove(kmi)

bpy.utils.unregister_class(ToggleSimplify)

if __name__ == "__main__":
register()

• Hi. I´ll test this code. Question: What if I do SHIFT+Q for the shortcut instead of "Q" on edit mode, or object mode? Is the interaction mode going to affect the script? Say I am in wireframe mode, will it toggle to full render and back to wireframe? Also: How do I clear the region using the same Shotcut key but just "tap" to clear render region? Could this line change to: "ToggleSimplify.bl_idname, type='SHIFT Q', value='PRESS', shift=True" ? – Pierre Schiller Mar 5 at 19:44
• I installed your .py addon, but when I press "Q", nothing happens. – Pierre Schiller Mar 5 at 19:58
• Shift+Q is already the shortcut key combination for that script. – JuhaW Mar 5 at 20:50
• Right now it´s triggering the render toggle first, then it launches area select mode. It should be area select mode first, end selecting area and when defined, then it should launch the toggle render function. Otherwise it beats the purpose of having a render preview. Could that be adjusted? – Pierre Schiller Mar 5 at 21:08
• I updated the script. – JuhaW Mar 6 at 9:53