On view2d.zoom_in/out

When adding this to the sequencer header menus, the function works but breaks the rest of the menu. Why?
layout.operator(“view2d.zoom_in”, text=“Zoom In”).delta = 1

Maybe because delta isn’t considered valid keyword argument of view2d.zoom_in, so the rest of the code doesn’t evaluate.

AttributeError: 'VIEW2D_OT_zoom_in' object has no attribute 'delta'

bpy.ops.view2d.zoom_in(zoomfacx=0, zoomfacy=0)
>>> bpy.ops.view2d.zoom_in(

Thanks. What is the correct syntax for using it? This doesn’t work:

    prop = layout.operator(st, "view2d.zoom", text="Zoom In"))
    prop.deltax = 1 
    prop.deltay = 1

That code wont work because you’re passing st where the layout expects an operator, and there’s an extra bracket at the end.

You could try something like this for modal:

prop = layout.operator("view2d.zoom", text="Zoom In")
prop.deltax = 1
prop.deltay = 1

or this for incremental zoom:

prop = layout.operator("view2d.zoom_in", text="Zoom In")
prop.zoomfacx = 0.5
prop.zoomfacy = 0.5

Thank you very much, now can I finally add those functions to the VSE menus. One interesting thing I noticed is that in the Sequencer, it is only possible to visually affect the X value - horizontal zoom - no matter if you set the zoomfacy value. So, for me, it doesn’t seem possible to zoom Y(vertical) in the sequencer - timeline through the api.

A workaround is to use the modal operator but instead of invoking its modal method, you can make it execute instead using the layout operator context.

If you want vertical zoom only, you can do something like this:

layout.operator_context = "EXEC_REGION_WIN"
zoom = layout.operator("view2d.zoom", text="Zoom Y")
1 Like

Thank you very much. Now you got the zoom stuff for the VSE working for me! :slight_smile: