As you know fps settings (Frame Rate) is set in the Rendering tab in Blender. How to I fetch that in script? I need to assign “fps” variable in the scrip a value of Frame Rate that is set in Blender’s Render tab. Thanks.
bpy.context.scene.render.fps = <i>desired frame rate</i>
The “actual” rate is
#some choices for datapaths scene = bpy.data.scenes["Scene"] # throws an error if no scene named "Scene" scene = bpy.data.scenes.get("Scene") # returns None if there is no scene named "Scene" scene = context.scene # context is passed via operator or panel method. actual_fps = scene.render.fps / scene.render.fps_base
scene.render.fps is only the integer part. To have non integer frame rates fps_base is used as a divisor. You can see there values by selecting custom for fps on the scene panel. You can also see the datapath on the tooltip when you mouse over any property.
if you set it using
>>> C.scene.render.fps = 23.222 >>> C.scene.render.fps 23 >>> C.scene.render.fps_base #( nope it doesn't set fps_base for you) 1.0
It will only be the integer part
>>> 23 / 23.22 0.9905254091300604 >>> C.scene.render.fps_base = 23 / 23.22 >>>
And now we have 23.22 as the displayed fps
That doesn’t work in 2.66
It does work in 2.66. ‘bpy.context.scene.fps = 30’ changes the frame rate to 30. fps = bpy.context.scene.fps assigns it to a variable. Although, what batFINGER said about fps_base should be taken into consideration.
hmm… I don’t need to change fps. I need to use existing value (read it and write into exporting file).
I am doing this: fps = bpy.context.scene.fps, then fps var is used to write it into the file (or at least it’s the thinking).
And I am getting this:
Traceback (most recent call last):
File “E:\blender-2.66\2.66\scripts\modules\addon_utils.py”, line 269, in enabl
mod = import(module_name)
File “E:\blender-2.66\2.66\scripts\addons\MD5Camera.py”, line 241, in <module>
class Export( bpy.types.Operator, ExportHelper ):
File “E:\blender-2.66\2.66\scripts\addons\MD5Camera.py”, line 250, in Export
fps = bpy.context.scene.fps
AttributeError: ‘_RestrictContext’ object has no attribute ‘scene’
Can we see the code? You might have to change where/when you assign the var.
I figured it out, thanks. I don’t even know why that line was there. I simply replaced with fps = 30 (initial setting) and it all works now.
you are not allowed to access bpy.context and bpy.data on addon registration, but if your write proper code, you don’t need it anyway. You can define a fps prop inside of an operator and set default argument to e.g. bpy.context.scene.fps, or get the fps inside of an invoke or execute function.