Script works in blender interface but not when I click ANIM?

This script has been nothing short of a life-saver for me. I can render still images of my model from many different angles without baby sitting the process. Plus, the still images are automatically named and saved. It is so much easier to use this script than it is to do it by selecting a camera, hitting render, waiting waiting waiting, saving the image, selecting the next camera, etc. I can use this script, hit ANIM and come back hours later to find all my still images.

So, what’s my problem? I got a crazy idea to make it even better. I decided to add 6 cameras into my scene with a lens size of 16. They are all placed at the exact same x/y/z location and point in different directions. These are used to make a cubic render. So, now I get many still images plus the still images necessary to make a 3d scrollable mov file.

To do this, the script must change the resolution of the render from 1280x1024 to 1000x1000. Unfortunately, the script will not do this properly on the first camera it encounters that requires the resolution change. In the blender interface, I have this script linked. I can go to the current frame button and advance the frame and see the camera change automatically. I can also see the resolution change when it is supposed to. However, when I click ANIM, the resolution does not change until one camera after it is supposed to change. So, if you look below, you will see that at frame 10, I want the resolution to change to 1000x1000. It does this in the blender interface when I manually advance to fram 10. But when I click ANIM, it does not change until 11. I have temporarily circumvented this issue by inserting a second camera that is the exact same as camera 10. So, it gets the correct image on the second try. But it is irritating that I have to render an image at the wrong size because the effect of the script when I hit ANIM is different than when I use the interface.

Sorry this is so long, but I wanted to clearly explain the problem. Any coding/blender experts that could help me fix this little irritating problem, I’d love to hear from you.


import Blender
from Blender import *

## Get scene data
cur = Scene.getCurrent()

## Get the current image render context
cntx = cur.getRenderingContext()  

def CheckCam():
   frame = Blender.Get("curframe")
   if (frame==1):
      Scene.getCurrent().setCurrentCamera(Object.Get("Camera01"))
      cntx.imageSizeX(1280)
      cntx.imageSizeY(1024)

   elif (frame==2):
      Scene.getCurrent().setCurrentCamera(Object.Get("Camera02"))
      cntx.imageSizeX(1280)
      cntx.imageSizeY(1024)

   elif (frame==3):
      Scene.getCurrent().setCurrentCamera(Object.Get("Camera03"))
      cntx.imageSizeX(1280)
      cntx.imageSizeY(1024)

   elif (frame==4):
      Scene.getCurrent().setCurrentCamera(Object.Get("Camera04"))
      cntx.imageSizeX(1280)
      cntx.imageSizeY(1024)

   elif (frame==5):
      Scene.getCurrent().setCurrentCamera(Object.Get("Camera05"))
      cntx.imageSizeX(1280)
      cntx.imageSizeY(1024)

   elif (frame==6):
      Scene.getCurrent().setCurrentCamera(Object.Get("Camera06"))
      cntx.imageSizeX(1280)
      cntx.imageSizeY(1024)

   elif (frame==7):
      Scene.getCurrent().setCurrentCamera(Object.Get("Camera07"))
      cntx.imageSizeX(1280)
      cntx.imageSizeY(1024)

   elif (frame==8):
      Scene.getCurrent().setCurrentCamera(Object.Get("Camera08"))
      cntx.imageSizeX(1280)
      cntx.imageSizeY(1024)

   elif (frame==9):
      Scene.getCurrent().setCurrentCamera(Object.Get("Camera09"))
      cntx.imageSizeX(1280)
      cntx.imageSizeY(1024)

   elif (frame==10):
      Scene.getCurrent().setCurrentCamera(Object.Get("Camera10"))
      cntx.imageSizeX(1000)
      cntx.imageSizeY(1000)

   elif (frame==11):
      Scene.getCurrent().setCurrentCamera(Object.Get("Camera11"))
      cntx.imageSizeX(1000)
      cntx.imageSizeY(1000)

   elif (frame==12):
      Scene.getCurrent().setCurrentCamera(Object.Get("Camera12"))
      cntx.imageSizeX(1000)
      cntx.imageSizeY(1000)

   elif (frame==13):
      Scene.getCurrent().setCurrentCamera(Object.Get("Camera13"))
      cntx.imageSizeX(1000)
      cntx.imageSizeY(1000)

   elif (frame==14):
      Scene.getCurrent().setCurrentCamera(Object.Get("Camera14"))
      cntx.imageSizeX(1000)
      cntx.imageSizeY(1000)

   elif (frame==15):
      Scene.getCurrent().setCurrentCamera(Object.Get("Camera15"))
      cntx.imageSizeX(1000)
      cntx.imageSizeY(1000)

CheckCam() 


Any experts willing to comment on this issue? Did I leave out important information which makes it hard to understand?

reap

I have written a script to render all the cameras in a scene, you might like to try it or see how its done.
http://blender.formworks.co.nz/
http://blender.formworks.co.nz/render_cameras/render_cameras.html

As for your problem you might try rendering the frames from your script,
ie. calling context.render() then context.saveRenderedImage(“myimage”)
As I do in my script, no gaurantee it will work but worth a go.
NOTE: That saveRenderedImage() was only added in 2.40

Hope that helps.