Temporarily suspend mouse wheel zooming?

Hello,

I’m fiddling about using the mouse wheel as an input, using the keyboard and mouse modules to intercept the events. The sketch below gives the idea.

For it to be useful, I would need to temporarily suspend the mouse wheel zooming the display. Does anyone have any suggestions how that may be done?

Best, Paul.

#! python3

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
import Rhino.Geometry as rg
import Rhino.Commands as rc
import Rhino.Input.Custom as ric

import System
import System.Drawing
import System.Collections.Generic
import math

#r: keyboard, mouse
import keyboard
import mouse

class GetCircleRadiusPoint (ric.GetPoint):

    def __init__(self, initial_radius):
        ric.GetPoint.__init__(self)
        self.line_color = System.Drawing.Color.FromArgb(255,0,0)
        self.keydown = False
        self.radius = initial_radius

    def HookaKey(self, key):
        keyboard.on_press_key(key, self.KeyboardDownfunc)
        keyboard.on_release_key(key, self.KeyboardUpfunc)

    def UnHook(self):
        keyboard.unhook_all()
        mouse.unhook_all()
        
    def MouseWheelFunc(self, event):
        if isinstance(event, mouse.WheelEvent):
            #print('wheel:', event.delta, event.time)
            self.radius += int(event.delta)*200
    
    def KeyboardDownfunc(self, event):
        if isinstance(event, keyboard.KeyboardEvent):
            if not self.keydown: 
                mouse.hook(self.MouseWheelFunc)
                self.keydown = True

    def KeyboardUpfunc(self, event):
        if isinstance(event, keyboard.KeyboardEvent):
            self.keydown = False
            mouse.unhook_all()

    def OnDynamicDraw(self, e):
        cplane = e.RhinoDoc.Views.ActiveView.ActiveViewport.ConstructionPlane()
        circle = rg.Circle(cplane, e.CurrentPoint, self.radius)
        e.Display.DrawCircle(circle, self.line_color)


def RunCommand():
    '''
    Change circle radius with mouse wheel while 'b' key is depressed
    '''
    gcp = GetCircleRadiusPoint(400)
    gcp.SetCommandPrompt('Radius')
    gcp.ConstrainToConstructionPlane(False)
    gcp.HookaKey('b')
    gcp.Get()
    gcp.UnHook()
    if gcp.CommandResult() != rc.Result.Success:
        return gcp.CommandResult()   
    radius = gcp.radius
    center_point = gcp.Point()
    gcp.Dispose()
    cplane = sc.doc.Views.ActiveView.ActiveViewport.ConstructionPlane()
    sc.doc.Objects.AddCircle(rg.Circle(cplane, center_point, radius))
    sc.doc.Views.Redraw()
    return rc.Result.Success

if __name__ == '__main__':
    RunCommand()

One idea would be to temporarily change the mouse wheel zoom scale factor to 1 which means zoom does not work:

import scriptcontext as sc
import Rhino.ApplicationSettings as appsettings
#get zoomscale
dbZoomScale = appsettings.ViewSettings.ZoomScale
#set zoomscale
appsettings.ViewSettings.ZoomScale = 1

and once ready, reset to the original value.

hth,

–jarek

Hi Jarek, That works, many thanks, Paul

If i want to activate mouse wheel zooming again,then?

Just set this one to 0.89, which I believe is default zoom scale factor setting:
appsettings.ViewSettings.ZoomScale = 0.89

Thank you.