4
$\begingroup$

I would like to add a custom frame rate slider in the timeline header, but I can't figure out how to do it.

enter image description here

I've tried to add following line in space_time.py (between line 75 and 77), but nothing happens:

layout.prop(scene, "render.fps", text="")

What am I missing?

Thanks.

$\endgroup$
2
  • 1
    $\begingroup$ depends on where you added that line.. $\endgroup$ Commented Jul 23, 2015 at 19:22
  • 1
    $\begingroup$ In "space_time.py" between lines 75 and 77 $\endgroup$
    – Zafio
    Commented Jul 23, 2015 at 20:55

2 Answers 2

5
$\begingroup$

Here is how it should be :

layout.prop(scene.render, "fps", text="fps") since the property is fps and it is in scene.render

$\endgroup$
0
4
$\begingroup$

I'd suggest write an Add-on instead of edit the python files which shipped with blender, simply because you can update Blender as you like.

Also it's fairly simple to append a property or a custom menu to the editor headers. Take a look into the python templates: Text Editor > Templates > Python > UI Menu. Key is to register bpy.types.EDITOR_TYPE.append(draw) and append a custom method to display the property.


Display a single property

To display a property in the timeline header use: bpy.types.TIME_HT_header.append(draw):

enter image description here

import bpy

def draw_frame_rate_property(self, context):
    scene = context.scene
    layout = self.layout

    # call the property
    layout.prop(scene.render, "fps", text="FPS")

def register():
    # lets add the menu to the timeline header via append or prepend
    bpy.types.TIME_HT_header.append(draw_frame_rate_property)

def unregister():  
    # remove header menu
    bpy.types.INFO_HT_header.remove(draw_frame_rate_property)

if __name__ == "__main__":
    register()

Display multiple properties as menu

For a custom frame rate menu in your timeline, create a menu class (see the UI Menu template) and call layout.menu for reference in your draw function. Following Add-on creates a new menu in the timeline header to edit all frame rate properties:

enter image description here

bl_info = {
    "name": "Set Frame Rate in Timeline",
    "description": "",
    "author": "poor",
    "version": (0, 0, 1),
    "blender": (2, 73, 0),
    "location": "Timeline > Header",
    "warning": "",
    "wiki_url": "",
    "tracker_url": "",
    "category": "Timeline"
}

import bpy

class CustomFrameRateMenu(bpy.types.Menu):
    bl_label = "Frame Rate"
    bl_idname = "RENDER_MT_framerate_menu"

    def draw(self, context):
        scene = context.scene
        layout = self.layout

        #frame rate properties
        layout.prop(scene.render, "fps_base", text="FPS Base")
        layout.prop(scene.render, "fps", text="FPS")
        layout.menu("RENDER_MT_framerate_presets", text="Presets", icon="SCENE")

def draw_frame_rate_menu(self, context):
    layout = self.layout
    layout.menu(CustomFrameRateMenu.bl_idname)

def register():
    bpy.utils.register_module(__name__)

    # lets add the menu to the timeline header via append or prepend
    bpy.types.TIME_HT_header.append(draw_frame_rate_menu)

def unregister():
    bpy.utils.unregister_module(__name__)

    # remove header menu
    bpy.types.INFO_HT_header.remove(draw_frame_rate_menu)

if __name__ == "__main__":
    register()

Note: Use bpy.types.EDITOR_TYPE.prepend() to display the property before the menu:

enter image description here


Further information:

$\endgroup$
2
  • $\begingroup$ Thanks, really useful! But the thing is, I also wanted to change the layout of the header elements: i.imgur.com/LF60YIS.png And I guess that wouldn't be possible with an addon, right? $\endgroup$
    – Zafio
    Commented Jul 25, 2015 at 20:23
  • 1
    $\begingroup$ @Zafio Right, you can only append and prepend, adding inbetween existing elements seems to be really hacky at the moment, see the answer (and the comments) of CoDEmanX: blender.stackexchange.com/questions/3393/… $\endgroup$
    – p2or
    Commented Jul 26, 2015 at 8:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .