I am creating a rotating knob in Blender for my GUI-project.

The knob has to be rendered in 64 different angles. Is there a way I can automate this extremely tedious process with a python script?

  1. Render the knob at 0° Z,
  2. Save the file
  3. Rotate knob 3°
  4. Render
  5. Save the file
  6. Repeat 64 times

I want to use the Cycles Render and a high-number of samples (1500-2000).

  • 5
    Why not animate the rotation and render an image sequence? – gandalf3 Aug 3 '14 at 23:30
up vote 5 down vote accepted

After some trial and error I found that this python script works for me:

import bpy, math

knob = bpy.data.objects["MyBlenderKnob"]
knob.rotation_mode = 'XYZ'

rotate_by = 4.21875   #How many degrees to rotate the knob for every step
start_angle = 45      #What angle to start from

for x in range(1,65):
    angle = (start_angle * (math.pi/180)) + (x*-1) * (rotate_by * (math.pi/180))
    knob.rotation_euler = ( 0, 0, angle )

    bpy.context.scene.render.filepath = "/Users/myfolder/KnobFrame%d.png" % (x)
    bpy.ops.render.render(write_still=True, use_viewport=True)

It grabs my blender object called "MyBlenderKnob" and rotates it 4.21875° on the Z-axis, then it renders it according to the current render-settings in the project. Then it saves the files in "myfolder".

Beautiful! A real timesaver.

  • 3
    re: ` 2.356 + (x*-1) * 0.0736` - why use magic numbers here? math.radians can convert degrees for you. – ideasman42 Aug 6 '14 at 10:05
  • Ok, thank you! Will try to implement it and update this post. – Daggepagge Aug 6 '14 at 10:08
  • 1
    Went to the time and trouble to recover my password to upvote you! – SingleStepper Nov 6 '16 at 17:55
  • Thank you @SingleStepper ! I removed the magic numbers now: converting between degrees and radials in the script instead. :) – Daggepagge May 15 '17 at 16:02
  • Or start_angle = math.radians(45) – batFINGER May 15 '17 at 16:06

You don't need to use a script to get 64 individual images. When rendering an animation while the output filetype is set to an image format each frame will be saved to an individual file.

  1. Set end frame to 64
  2. Set filetype to single image eg. png, jpeg, tiff...
  3. Go to frame one and insert a keyframe for rotation
  4. Go to last frame and rotate the knob 189 degrees
  5. Insert keyframe for rotation
  6. Go to graph editor or dopesheet and select all keyframes
  7. Press T and select linear
  8. Render animation

Step 6 and 7 ensures the rotation is the same amount each frame. By default the interpolation will be bezier which will give less rotation at each end and faster in the middle (ease-in and ease-out). You can get around this step if you set the default interpolation to linear in the editing preferences.

  • Its possible the object is animated already - so its not necessarily a solution to render an animation. – ideasman42 Aug 5 '14 at 22:40

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.