Issue with writing particle location to text file

40 Views Asked by At

I'm trying to (1) get the x and y locations of the individual particles of a particle system and (2) write it to a text file. This is just so I can use the text file to calculate the number of times the particles move past the origin.

This is not the best way to do this, I imagine (advice appreciated!). But I'm not very good at python scripting in Blender, hence the current method.

So far my code creates the text file but nothing is written on it. The following is the code excerpt, which incorporates what I've found online:

### create text file 
filepath='C:/SomeDirectory/textfile.txt'
file= open(filepath,'w')

### assign variable to particle system 
### (I had previous added a modifier to a cube for the particle system)

chosenParticles = bpy.data.objects['Cube'].particle_systems['part'].particles

### run loop for each frame in my animation
for i in range(totalFrames)
    bpy.context.scene.frame_set(i)
    for particle in chosenParticles:
      locY=particle.location.y 
      locX=particle.location.x
      file.write(str(locX)+str(locY)+str(i))

file.close()
0

There are 0 best solutions below