Problems refreshing a loaded image as a texture

(BaDbOyHeRe) #1

Im trying to grab an image and assign the texture to a Plane 10 times, every 3 seconds. My problem is that I can’t seem to refresh the file for each load. That is, if I load a different filename each time, it updates the texture. However, if I try to do this with only one file that is externally updated, it just keeps the original image. What can I do to clear out the image from memory so that it actually loads it again? Could I have python rename the image and save it prior to loading it for the texture, and then have it load the image using sequential filename". Like test001.bmp, then the next cycle will retrieve test002.bmp. Here is part of the code:

import Blender 
import time
Num = 0
while Num < 10:

	ob = Blender.Object.get("Plane") 
	me = ob.getData() 
	img = Blender.Image.Load("//textures/test1.bmp")
	if img:
	   if me.hasFaceUV():
	      for f in me.faces: 
	         f.image = img 
	         f.flag = Blender.NMesh.FaceModes.TEX 
	         f.transp = Blender.NMesh.FaceTranspModes.SOLID 
	      print "Mesh has no uv coords" 
	   print "Can't load image"  
	Num += 1
	print "updating image...", time.sleep(3), Num

Any suggestions?

(BaDbOyHeRe) #2

OK, I have been learning python and blender’s new api. I can even notice my own errors on the above code. Last night I figured out alot of basics to the language. It wll be awhile before I can call myself proficent with it, but thanks to the community, I have learned alot already. As for my above post, I am using this to push myself into learning more. Even if I knew :wink: that there is no way to accomplish this with the current version, I must try until I exhaust all avenues.


(saluk) #3

If you import os, I think you can change the name of the filename each time using os.rename(path,newname). I’m not totally certain, or even sure if this would fix the problem, but check it out:)

(BaDbOyHeRe) #4

I am looking into that. I found out how to copy the file to another directory. so, mabe if I rename it, save it, then load it, it will update? or use a counter to switch between 2 files e.g. if odd, if even. I even sucessfully compared the image modified date/time with the blend file’s last opened date/time so it will not get the file until it is updated. I’m not sure exactly how I will get it to work, but I will eventually. I am using this to grab images from my webcam(saved locally) and it has an option to save multiple sequential names, and can let me set it to save image01 1st time then image02 2nd time then image01 the third and so on.