0

is there a way to customize the Alt + Mouse Wheel which works in most editors that when you reach the end frame you can jump back to start?
is it something I don't see in settings or do I need a script for that and how can I do it by script if so .

I'm not looking for other hotkeys to jump to start and end, I wanna use that specific hotkey and move in timeline normally but instead of passing by the end frame, jump back to start or being stuck at the start get back to end frame...
like in a walk cycle animation this way you can easily see the transition between end and starting over

MohMehdi
  • 480
  • 2
  • 11
  • SHIFT-Left arrow takes you to the start and SHIFT-Right arrow to the end of the timeline. – John Eason Sep 15 '21 at 08:25
  • @JohnEason yeah but for that you need to take one of your hands of the mouse or keyboard . if there was a way to do it just like I said that would be nice – MohMehdi Sep 15 '21 at 09:29
  • can do most things in blender via a script Please clarify what you do want, not what you don't. Are we talking about scrubbing the time line with the scroll wheel and if it goes past end points reverts to the other? – batFINGER Sep 15 '21 at 15:24
  • @batFINGER question is very self explaining . that link you sent helped alot i just need to look up for more stuff to make the script for it – MohMehdi Sep 15 '21 at 15:28

2 Answers2

0

Edit the keymap.

As commented by @John Eason these are already mapped to SHIFT and left arrow for go to start, and right to end.

Can search for keymaps by keypress

enter image description here

Or name, if unsure hover over the button that does it

enter image description here

Once found change to suit.

enter image description here

Here I've altered it to ALT + middle mouse click.

Save User Preferences to make change permanent.

batFINGER
  • 84,216
  • 10
  • 108
  • 233
  • i know i can change the hotkey for that but what im saying is to change the behavior of a specific hotkey when something happens. it is a small change but i guess that way its easier for something like a walk cycle . so this wont be the answer – MohMehdi Sep 15 '21 at 14:55
  • Clarify any details by editing it into your question. Do you want to match the frame range to current objects action range rather than scene. There are answers relating to that question. – batFINGER Sep 15 '21 at 14:58
  • yeah maybe that would work – MohMehdi Sep 15 '21 at 15:05
  • https://blender.stackexchange.com/questions/27889/how-to-find-number-of-animated-frames-in-a-scene-via-python – batFINGER Sep 15 '21 at 15:13
-1

Why Even Do this

there are several options to monitor the transitions in frames but in my experience the best way is to use the mouse scroll wheel since you have more control over speed and its easy to use . It's like classic animation when animators flip back and forth paper between their fingers.

but when you are making a cycle animation which is used a lot in game animations, there is one thing that is annoying and its how you cant see the transition from end frame to starting over as easy.

it is a small change but I think it worth it.


So here is a way to make this work
basically we disable the old behavior and make a new one that does the same old behavior and just checks for the end and start frame then does the expected thing

Disable Default Hotkeys

Edit -> Preferences -> Keymap

  1. set the search type to Key-Binding
  2. search for "wheel"
  3. scroll a bit and find Frames section
  4. and disable both Frame Offsets

How to Make The Script

So to make a function and assign a hotkey to it we need an Operator
which has an execute function where our logic will be
and when we assign a hotkey to the operator ,when the keys are pressed(event happens) this function will be called

we want to make this as an add-on ,so we add some info about it in bl_info

First Step

as you can see the operator class has some basic properties like an ID , label and more that we can fill in and some more info

bl_info = {
    "name": "Better_Scroll_Time",
    "blender": (2, 80, 0),
    "category": "Object",
}

import bpy from bpy.props import * import addon_utils

class ScrollWheelTime(bpy.types.Operator): """Sets the time in range""" # Use this as a tooltip for menu items and buttons. bl_idname = "object.scroll" # Unique identifier for buttons and menu items to reference. bl_label = "Better Time Scroll Wheel" # Display name in the interface. bl_options = {'REGISTER', 'UNDO'} # Enable undo for the operator.

def execute(self, context):        # execute() is called when running the operator.    
    # logic


    return {'FINISHED'}            # Lets Blender know the operator finished successfully.

Execute

direction: IntProperty()  #outside of execute function as a class member
def execute(self, context):
    #logic
    scn = context.scene 
    current_frame = scn.frame_current
    current_frame+=self.direction
    scn.frame_set(current_frame)

    if not scn.frame_start <= current_frame <= scn.frame_end:
        scn.frame_set(scn.frame_start if self.direction>=1 else scn.frame_end)

    return {'FINISHED'}        

  • so if you look at blender keymaps in Preferences you can find Operations with some properties that we can provide too, with bpy.props functions like IntProperty()
  • we need a reference to the scene we are in to access things like start and end frame of the scene
  • increase or decrease current frame with the amount of direction which will be set to +1 and -1 based on the shortcut
  • if current frame is not between start and end frame of the scene based on the direction we decide where to put the frame cursor
  • we tell blender this operation is finished

Register

addon_keymaps = []                 #outside of function

def register():
bpy.utils.register_class(ScrollWheelTime) # Add the hotkey wm = bpy.context.window_manager kc = wm.keyconfigs.addon if kc: km = wm.keyconfigs.addon.keymaps.new(name = "Window",space_type='EMPTY', region_type='WINDOW') km_up = km.keymap_items.new(ScrollWheelTime.bl_idname, type='WHEELUPMOUSE', value='PRESS', alt=True) km_down = km.keymap_items.new(ScrollWheelTime.bl_idname, type='WHEELDOWNMOUSE', value='PRESS', alt=True)

    km_up.properties.direction = -1     # setting the default property value for wheel up
    km_down.properties.direction = +1    # setting the default property value for wheel down

    addon_keymaps.append((km, km_up))
    addon_keymaps.append((km, km_down))

  • here we register our operation class so we can use if as an addon
  • then we make a keymap using wm.keyconfigs.addon.keymaps.new and set its parameters to name = "Window", space_type ='EMPTY', region_type ='WINDOW'
    so our hotkey works in all editor windows
  • then we assign our shortcuts to the operation class
  • we can set a default value to our custom properties that defined as class member using bpy.props
  • we save this hotkeys so we can remove them in unregister function

to make things clear in unregister function we remove our hotkeys

you can see completed script here (code could have some clean ups)

bl_info = {
    "name": "Better_Scroll_Time",
    "blender": (2, 80, 0),
    "category": "Object",
}
#---------------------------------------add-on-info------------------------------------#

import bpy from bpy.props import * import addon_utils

class ScrollWheelTime(bpy.types.Operator): """Sets the time in range""" # Use this as a tooltip for menu items and buttons. bl_idname = "object.scroll" # Unique identifier for buttons and menu items to reference. bl_label = "Better Time Scroll Wheel" # Display name in the interface. bl_options = {'REGISTER', 'UNDO'} # Enable undo for the operator. direction: IntProperty()

def execute(self, context):        # execute() is called when running the operator.    
    # logic
    scn = context.scene 
    current_frame = scn.frame_current
    current_frame+=self.direction
    scn.frame_set(current_frame)

    if not scn.frame_start <= current_frame <= scn.frame_end:
        scn.frame_set(scn.frame_start if self.direction>=1 else scn.frame_end)

    return {'FINISHED'}            # Lets Blender know the operator finished successfully.


addon_keymaps = []

def register():
bpy.utils.register_class(ScrollWheelTime) # Add the hotkey wm = bpy.context.window_manager kc = wm.keyconfigs.addon if kc: km = wm.keyconfigs.addon.keymaps.new(name = "Window",space_type='EMPTY', region_type='WINDOW') km_up = km.keymap_items.new(ScrollWheelTime.bl_idname, type='WHEELUPMOUSE', value='PRESS', alt=True) km_down = km.keymap_items.new(ScrollWheelTime.bl_idname, type='WHEELDOWNMOUSE', value='PRESS', alt=True)

    km_up.properties.direction = -1     # setting the default property value for wheel up
    km_down.properties.direction = +1    # setting the default property value for wheel down

    addon_keymaps.append((km, km_up))
    addon_keymaps.append((km, km_down))

print("Installed Better Scroll Time !")

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

 # Remove the hotkey
for km, k in addon_keymaps:
    km.keymap_items.remove(k)
addon_keymaps.clear()



This allows you to run the script directly from Blender's Text editor

to test the add-on without having to install it.

if name == "main": register()

MohMehdi
  • 480
  • 2
  • 11
  • 2
    context is already passed to the operator methods so you can replace bpy.context.* by context.* for all calls/properties and when declaring a variable use it, see: https://pasteall.org/oUiT/raw Also consider that this is no regular forum and link-only answers are discouraged, if the link goes down so does the answer hence the downvote I guess. – brockmann Sep 16 '21 at 08:27
  • @brockmann thanks for the tip , I'm new to blender scripting, so should I delete my answer and for example add the link to a comment or no link at all? – MohMehdi Sep 16 '21 at 08:37
  • 2
    No problem. I'd suggest add a complete explanation what it does, why this is helpful at all and add your code to the answer, see: https://blender.stackexchange.com/help/how-to-answer Your question isn't clear enough too, no wonder batFINGER's answer is a bit off (IMHO). Also consider using a frame_handler and limit the hotkey to the timeline area. – brockmann Sep 16 '21 at 08:55
  • thank you . I'll try to make myself more clear next time – MohMehdi Sep 16 '21 at 09:04
  • Please do. Re answer, can be achieved with one operator. For example the Jump to Endpoint operator has a boolean property last_frame which if true goes to end, else start. Recommend do same here, rather than have two near identical operators. – batFINGER Sep 16 '21 at 11:15
  • @batFINGER but how can we check if wheel up or down to move current frame back or forward? – MohMehdi Sep 16 '21 at 11:49
  • Use as with other keymaps. In answer below, last_frame is unchecked so it jumps to start frame. If you have for example a boolean forwards then if self.forwards: df = 1 else -1 Set forwards true in 'WHEELUPMOUSE' keymap. Could instead use an int for speed, like a 16x scrub. – batFINGER Sep 16 '21 at 12:11
  • @batFINGER i think i dont fully understand. we can pass something to the class when a keymap event happens? or you mean have one operator to set the current frame to last frame and start and have defualt hotkeys for scrubing(cuz this wont work they will have conflict) – MohMehdi Sep 16 '21 at 12:15
  • What makes you think I mean something that won't work? WIll try and make it clear for you. The operator that moves to first or last frame is one operator. As is Frame Offset. Both have operator properties so a different behavior can be set via different keymap. (Just like changing the properties directly in the operator popup in the UI) This avoids having two basically identical operators (as in answer here). – batFINGER Sep 16 '21 at 12:22
  • @batFINGER im sorry if i cant understand. im trying. but how could that work? two operators one of them wants to set frame cursor to start and other one which is Frame Offset also wants to set the frame cursor to the next frame after end frame – MohMehdi Sep 16 '21 at 12:27
  • 1
    One scrubbing operator going backwards or forwards depending on a prop. If the frame goes past end return to start and continue going forwards , if it goes pre start go to end and continue going backwards. – batFINGER Sep 16 '21 at 12:34
  • @batFINGER got it, i didnt know about props . thank you for your time, i will change my answer soon – MohMehdi Sep 16 '21 at 14:30