Python Lesson I

Python scripting resources
User avatar
tsn
Posts: 872
Joined: Fri Oct 27, 2006 10:36 am

Python Lesson I

Postby tsn » Thu Jan 11, 2007 9:54 am

For the sake of completeness, here is the link to the first tutorial:

[ Link has expired. Tutorials will be revised during the next weeks ]


User avatar
MightyG
Posts: 73
Joined: Mon Jun 04, 2007 8:44 pm

Python Lesson I

Postby MightyG » Thu Jun 14, 2007 8:18 pm

Hey man

Just finished lesson 1. Awesome!! Im so glad this material is available. The power of the script is amazing

thanks!
-Adam
make today be the tomorrow you've been dreaming of

orr
Posts: 60
Joined: Mon Sep 03, 2007 5:18 pm

Python Lesson I

Postby orr » Wed Sep 05, 2007 7:07 am

I am fairly new to python so I tried this one ... but always if I try to execute this script or the "homework" one my rf crashes :(
can anyone help me?

User avatar
tsn
Posts: 872
Joined: Fri Oct 27, 2006 10:36 am

Python Lesson I

Postby tsn » Wed Sep 05, 2007 11:14 am

Hello orr,

the possibilities for the crashes are endless and it´s impossible to say, why the scripts don´t work via a remote session. I´d need the scene file to support you. Is there a way for you to make it available (ftp, upload server, homepage..)?

orr
Posts: 60
Joined: Mon Sep 03, 2007 5:18 pm

Python Lesson I

Postby orr » Thu Sep 06, 2007 9:28 am

well I wrote that code down a third time and then it didn't crash o0 ...still I am not sure if I do everything right here :D
thanks for offering me your help

omarpac
Posts: 118
Joined: Tue Dec 11, 2007 7:42 pm

Python Lesson I

Postby omarpac » Sat Feb 23, 2008 5:12 pm

how can i check if my script is working?
and when i check for syntax error it tells me theres an error at the marked line below

emitter = scene.getEmitter("Circle01") TELLS me the Error is here
particle = emitter.getFirstParticle()

while particle:

velocity = particle.getVelocity()
velocityY = velocity.getY()
height = particle.getPosition()
heightY = height.getY()

if (heightY > 2) :
new_velocityY = veloctiyY + 2.0
new_velocity = Vector.new(0.0, new_velocityY, 0.0)
particle.setVelocity(new_velocity)

particle = particle.getNextParticle()
(:helloo all:)

omarpac
Posts: 118
Joined: Tue Dec 11, 2007 7:42 pm

Python Lesson I

Postby omarpac » Sat Feb 23, 2008 5:21 pm

its a syntax error but when i check for integrity...((donnow wat that is it tells me its okay))
(:helloo all:)

shaun_michael
Posts: 4766
Joined: Sun Sep 10, 2006 8:04 am

Python Lesson I

Postby shaun_michael » Sat Feb 23, 2008 5:39 pm

Code: Select all

def onSimulationStep():
   emitter = scene.getEmitter("Circle01")
   particles = emitter.getParticles()

   for particle in particles:
      velocity = particle.getVelocity()
      velocityY = velocity.getY()
      height = particle.getPosition()
      heightY = height.getY()

      if (heightY > 2) :
         new_velocityY = velocityY + 2.0
         new_velocity = Vector.new(0.0, new_velocityY, 0.0)
         particle.setVelocity(new_velocity)

      particle = particle.getNextParticle()

I changed the getFirstParticle to getParticles and altered the tabs (although you may well have had them right its just that you didn't post it as code). Changed the while to a for loop, and also, the first line after the if statement, velocity was spelt wrong.

Seems to work fine now.

Shaun

shaun_michael
Posts: 4766
Joined: Sun Sep 10, 2006 8:04 am

Python Lesson I

Postby shaun_michael » Sat Feb 23, 2008 5:50 pm

Code: Select all

def onSimulationFrame():

  emitter = scene.getEmitter("Circle01")
  particle = emitter.getFirstParticle()

  while particle:

    velocity = particle.getVelocity()
    velocityY = velocity.getY()
    height = particle.getPosition()
    heightY = height.getY()

    if (heightY > 2) :
      new_velocityY = velocityY + 2.0
      new_velocity = Vector.new(0.0, new_velocityY, 0.0)
      particle.setVelocity(new_velocity)

    particle = particle.getNextParticle()

And another version using the while statement.

Shaun

shaun_michael
Posts: 4766
Joined: Sun Sep 10, 2006 8:04 am

Python Lesson I

Postby shaun_michael » Sat Feb 23, 2008 6:58 pm

Actually, I'd quite like to know the benefit of using one (while or for) over the other.

Shaun


Return to “Python Tutorials and Resources”

Who is online

Users browsing this forum: No registered users and 1 guest