Blenders default command for zoom selected

Is it possible to tweak Blender’s default command for zoom selected (num.) ? to often the camera zooms in to close. Would it be possible to write a script that fix this?


No, “View Selected” has no options other than “do that in all regions”. Only possible “fix” would be to implement your own custom operator in Python.

Here’s my humble go at trying to code it. It’s only partly functional unfortunately.
Where this script fails is that for some reason the first time you call it - it’s a regular ViewSelected. You press the hotkey again than it does zooms out after View Selected.
This means you have to tap your hotkey 2x in order to get desired effect.
Maybe someone can help us figure out a way to fix it.

What you need to do is copy/paste this code in Notepad (or such), save as whatever name.py (using UTF-8 Encoding in Notepad).
Copy the file in your Addons folder (C:\Users\YOURUSERNAME\AppData\Roaming\Blender Foundation\Blender\2.76\scripts\addons)
Run Blender and activate “0rAngE View Selected” addon
go into the input editor and add a new hotkey in 3D View>3d View (Global)
paste this into the field:
view_selected.zoomout
(hit Save User Settings if you want to have it load on startup)


bl_info = {
    "name": "0rAngE View Selected",
    "author": "0rAngE",
    "category": "3D View"}

import bpy

class ViewSelectedZoomOut(bpy.types.Operator):
    bl_idname = "view_selected.zoomout"
    bl_label = "ViewSelected and ZoomOut"
    
    def execute(self, context):
        #View Selected
        bpy.ops.view3d.view_selected()
        #Zoom Out
        bpy.ops.view3d.zoom(delta=-1)
        bpy.ops.view3d.zoom(delta=-1)
        return {'FINISHED'}
    
# Register / Unregister Classes    
def register():
    bpy.utils.register_class(ViewSelectedZoomOut)


def unregister():
    bpy.utils.unregister_class(ViewSelectedZoomOut)
    
    wm = bpy.context.window_manager

    if wm.keyconfigs.addon:
        for km in addon_keymaps:
            for kmi in km.keymap_items:
                km.keymap_items.remove(kmi)

            wm.keyconfigs.addon.keymaps.remove(km)

    # clear the list
    del addon_keymaps[:]

if __name__ == "__main__":
    register()

Use Shift + F. This lets you move back and forth and side to side like a 1st person game using the W S A D keys. Hold the shift down to speed up movement. You can swing the view port around with mouse in this mode.

Stan, Thanks for the answer!, i guess the follow up question to that is: how hard is that to do? Is it a massive task?

Orange, Thanks! I will give that a try and get back to you with the result. This is so awesome!

0rAngE, jimpaw80, this operator should perform nicer, and gives a parameter to tweak in input editor (jimpaw80, replace just the class in original code):


class ViewSelectedZoomOut(bpy.types.Operator):
    bl_idname = "view_selected.zoomout"
    bl_label = "ViewSelected and ZoomOut"
    
    zoom_delta = bpy.props.IntProperty(name="Zoom Out", description="Steps to zoom out", min=0, max=10, default=4)
    
    def execute(self, context):
        #View Selected
        bpy.ops.view3d.view_selected()
        #Zoom Out
        for i in range(self.zoom_delta):
            bpy.ops.view3d.dolly(delta=1, mx=context.region.width/2, my=context.region.height/2)
        return {'FINISHED'}

Okay i got it to work. You cannot have the smooth activated while using this then it does not work,but if you deactivate that it works with just one click. I have not tried it on my pie but will try it out tomorrow.

Stan, that’s nice to be able to tweak from the Input Editor, thanks!
jimpaw80, nice catch of Smooth View being the culprit there!

I like how this is working now, this is gonna be my default View Selected command :slight_smile: