Need help with Python script (LOOP)

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

BaDbOyHeRe
Posts: 5
Joined: Fri Oct 25, 2002 9:58 pm

Need help with Python script (LOOP)

Postby BaDbOyHeRe » Sat Oct 26, 2002 4:12 am

I'm new to python and am having a little bit of a problem finding tutes relating to creating a loop. I have a plugin in mind and I need to have python import a file. My problem is that I need it to get the same file more than once, actually almost continously. I read somewhere awhile ago (cant recall exactly where) that you can perform the loop according to an event. How can I create a loop? Also, is it possible to have python compare changes within a file prior to getting it? :idea: :?: example: have python compare the file's modified date and time with the last one imported? This would be more desireable for the script to minimize cpu load. Any suggestions?
DELETE FROM this_planet
WHERE 1 = "Unchallenged";-)

Anthony
Posts: 16
Joined: Fri Oct 25, 2002 5:14 am

Postby Anthony » Wed Oct 30, 2002 5:18 am

All those things are very easy to do in python. Here is an example to get you started:

Code: Select all

for i in range(5):
   file = open("filename.ext", "rb")
   print file.read()
   file.close()

BaDbOyHeRe
Posts: 5
Joined: Fri Oct 25, 2002 9:58 pm

Postby BaDbOyHeRe » Wed Oct 30, 2002 5:00 pm

Thank you very much. very simple indeed. I've been hitting the python docs and learning much lately. I hope to be able to give help in the future to a newbie like myself....thanks again

BaDbOyHeRe
DELETE FROM this_planet

WHERE 1 = "Unchallenged";-)

dwmitch
Posts: 2
Joined: Sat Nov 16, 2002 5:23 am

Postby dwmitch » Fri Nov 22, 2002 5:45 am

While we're on the subject of loops, how would one go about making a "ping pong" loop? I'm trying to make a script that will have a lamp's energy go from 0.5 to 1.0 to 0.5 until the end of the animation, but nothing I do works. I've tried:
_____________________________________________________________
import Blender

obj = Blender.Object.Get("LampObj")

la = obj.data

la.Energ = 0.5

if la.Energ <= 1.0:
la.Energ = la.Energ + 0.1

if la.Energ >= 0.5:
la.Energ = la.Energ - 0.1
_____________________________________________________________ I've tried all forms of variants, but with no success.
Like a curr
I walk
the streets
the dirt beneath
their feet.

comiac
Posts: 1
Joined: Tue Nov 19, 2002 5:53 pm

Ping Pong

Postby comiac » Fri Nov 22, 2002 11:35 am

Although my python is not up to speed, my programming is. You should have a variable that says direction you can change this to a negative or positive number and add this to the var la.Energ. Another way to approach this would be to have it me dependent on the current frame number by doing a modulus of the frame number.

BTW your code is not working because the statements are being executed one after the other. is la.Energ is 0.5 this is less than 1.0 and therefore it will be changed to 0.6 but the next line is also true since 0.6 is more than 0.5 the value will be decreased to 0.5

if la.Energ <= 1.0:
la.Energ = la.Energ + 0.1

if la.Energ >= 0.5:
la.Energ = la.Energ - 0.1

Hope this help and not confuse more!


Return to “Python”

Who is online

Users browsing this forum: No registered users and 1 guest