Engineering aspects of Realflow - Basic Questions
Re: Engineering aspects of Realflow - Basic Questions
This is the main directory of the project : C:/Users/Gabor/scenes/test/
and I want to do a particle_version02 directory, to separate the bin files, what the simulation makes, from the txt files.
the Syntax check says, this is wrong:
position = particle.getPosition()
and I want to do a particle_version02 directory, to separate the bin files, what the simulation makes, from the txt files.
the Syntax check says, this is wrong:
position = particle.getPosition()
-
- Posts: 2880
- Joined: Mon Oct 15, 2007 4:09 pm
- Contact:
Re: Engineering aspects of Realflow - Basic Questions
Please post the exact code you're using and do it in the code brackets so the tabs and spaces are preserved too.bmecohen wrote:This is the main directory of the project : C:/Users/Gabor/scenes/test/
and I want to do a particle_version02 directory, to separate the bin files, what the simulation makes, from the txt files.
the Syntax check says, this is wrong:
position = particle.getPosition()
Code: Select all
# Like this, see the spaces and tabs are preserved
def foo(bar):
print bar
foo('This is a test')
WhenPicsFly | Debian GNU/Linux
Re: Engineering aspects of Realflow - Basic Questions
Code: Select all
# Creates a file object that Python can write to
file = open("C:/Users/Gabor/scenes/test/particles_version02/001.txt", "w")
# Gets the emitter and the first particle of the emitter
emitter = scene.getEmitter("Circle01")
particle = emitter.getFirstParticle()
# Loop through all particles and write out their ID and position
while particle:
position = particle.getPosition()
id = particle.getId()
file.write("%s %s %s %s" % (id,position.getX(),position.getY(),position.getZ()))
particle = particle.getNextParticle()
# Close the file object when done, this is a good practice
file.close()
I use this as a batch script, it should be an event script in every simulation frame?
After that, syntax check says a problem in this line: particle = emitter.getFirstParticle()
thanks in advance for the huge help!
Re: Engineering aspects of Realflow - Basic Questions
I think the problem is incorrect indentation/ spacing. In Python spaces and tabs work just like parenthesis in other programming languages. Whitespace is not ignored, but part of the language. When I was new to Python, I hated that, too. In order to make position.getPosition() a part of your while- loop, do it like this.
Some more detailesd info on that matter:
http://docs.python.org/release/2.5.1/re ... ation.html
Code: Select all
# Loop through all particles and write out their ID and position
while particle:
position = particle.getPosition()
id = particle.getId()
file.write("%s %s %s %s" % (id,position.getX(),position.getY(),position.getZ()))
particle = particle.getNextParticle()
http://docs.python.org/release/2.5.1/re ... ation.html
Re: Engineering aspects of Realflow - Basic Questions
You were right, the code is now working! thank you!
I want to make a further development of the code, so I did a few improvments where I got error messages.
This is the start because I want write out the particle data in every frame and I want to make a "file export directory chooser"
The syntax check says that it is an error in the line of file = open and I don't know how to get the root_path and current_frame correctly. I think it will be a integer to string problem or something.
Other "issue" is in the txt file
and the output data is not what I wanted.
The txt should like this in order: ID PosX PosY PosZ VelX VelY VelZ Den Pres
but my txt is like this: ID PosX PosY PosZ VelX VelY VelZ ? ? ? /I don't see the density, and the pressure correctly, because the density should be greater than 0.4 or something if I use it basically as 1000/
Also afterwards I don't see any other particle ID just the first one. Maybe I misunderstand the code entirely, but I want a code like this:
I want to make a further development of the code, so I did a few improvments where I got error messages.
Code: Select all
current_frame = scene.getCurrentFrame()
root_path = scene.getRootPath()
Code: Select all
form = GUIFormDialog.new()
form.setTitle("Export to TecPlot")
form.addStringField("Root Path", root_path+"/"+"export/")
Code: Select all
if ( form.show() == GUI_DIALOG_ACCEPTED ):
emitter_export = scene.getEmitter(emitterNameList[form.getFieldValue("Choose emitter for export")])
particle = emitter_export.getFirstParticle()
# Creates a file object that Python can write to
file = open( root_path + current_frame ".txt", "w")
Other "issue" is in the txt file
Code: Select all
while particle:
id = particle.getId()
position = particle.getPosition()
velocity = particle.getVelocity()
density = particle.getDensity()
pressure = particle.getPressure()
file.write("%s %s %s %s %s %s %s %s %s" % (id,position.getX(),position.getY(),position.getZ(),velocity.getX(),velocity.getY(),velocity.getZ(),density,pressure))
particle = particle.getNextParticle()
The txt should like this in order: ID PosX PosY PosZ VelX VelY VelZ Den Pres
but my txt is like this: ID PosX PosY PosZ VelX VelY VelZ ? ? ? /I don't see the density, and the pressure correctly, because the density should be greater than 0.4 or something if I use it basically as 1000/
Also afterwards I don't see any other particle ID just the first one. Maybe I misunderstand the code entirely, but I want a code like this:
Code: Select all
VARIABLES = "id" "x" "y" "z" "vx" "vy" "vz" "density" "pressure"
ZONE F=POINT, STRANDID=1, SOLUTIONTIME=0.03
109616 0.786 -0.185 0.063 0.033 0.006 0.032 1049.749 304.752
109615 0.786 -0.177 0.063 0.001 0.005 0.003 1035.493 176.532
109614 0.786 -0.158 0.061 -0.005 -0.006 -0.007 1013.543 -1.258
-
- Posts: 2880
- Joined: Mon Oct 15, 2007 4:09 pm
- Contact:
Re: Engineering aspects of Realflow - Basic Questions
Get the basics of what you want working before you start adding a GUI and things that require string manipulation like the root path. Then go back and work out those non-essential items. Doing things one step at a time like that will make the debugging much easier to do.
WhenPicsFly | Debian GNU/Linux
Re: Engineering aspects of Realflow - Basic Questions
You are right...the most important problem is to fix the output data: I see only one particle id, and after just values what is look like position and velocity
The txt should like this in order: ID PosX PosY PosZ VelX VelY VelZ Den Pres
but my txt is like this: ID PosX PosY PosZ VelX VelY VelZ ? ? ? /I don't see the density, and the pressure correctly, because the density should be greater than 0.4 or something if I use it basically as 1000/
Also afterwards I don't see any other particle ID just the first one. Maybe I misunderstand the code entirely, but I want a code like this:
Code: Select all
while particle:
id = particle.getId()
position = particle.getPosition()
velocity = particle.getVelocity()
density = particle.getDensity()
pressure = particle.getPressure()
file.write("%s %s %s %s %s %s %s %s %s" % (id,position.getX(),position.getY(),position.getZ(),velocity.getX(),velocity.getY(),velocity.getZ(),density,pressure))
particle = particle.getNextParticle()
but my txt is like this: ID PosX PosY PosZ VelX VelY VelZ ? ? ? /I don't see the density, and the pressure correctly, because the density should be greater than 0.4 or something if I use it basically as 1000/
Also afterwards I don't see any other particle ID just the first one. Maybe I misunderstand the code entirely, but I want a code like this:
Code: Select all
VARIABLES = "id" "x" "y" "z" "vx" "vy" "vz" "density" "pressure"
ZONE F=POINT, STRANDID=1, SOLUTIONTIME=0.03
109616 0.786 -0.185 0.063 0.033 0.006 0.032 1049.749 304.752
109615 0.786 -0.177 0.063 0.001 0.005 0.003 1035.493 176.532
109614 0.786 -0.158 0.061 -0.005 -0.006 -0.007 1013.543 -1.258
Re: Engineering aspects of Realflow - Basic Questions
In my code, as I can see, the last particle data is overwrite eveything. So when a new particle created the datas from the old one is gone.
I would like to create a txt file, with all the particles, to write out just for the current frames position velocity etc. So for the frame 2 - frame 1 = change of distance in all particles etc.
I saw in the scripting reference an example:
in this, the code is working, all the particles id is visible in the messages box.
I would like to create a txt file, with all the particles, to write out just for the current frames position velocity etc. So for the frame 2 - frame 1 = change of distance in all particles etc.
I saw in the scripting reference an example:
Code: Select all
# Iterate the list of particles and write out their ids.
currentParticle = emitter.getFirstParticle()
while currentParticle:
scene.message( str( currentParticle.id ) )
currentParticle = currentParticle.getNextParticle()
Re: Engineering aspects of Realflow - Basic Questions
I divided this topic to specific problems because it's to complex. Thanks for everyone the help!