Python Examples and Ideas
Aside from theoretical considerations, practical exercises are the best way to learn something new – learning by doing is also a valid concept for programming languages. All the following examples include the rules and ideas from the previous chapters to show you how these things work in practice. You will loop through emitter particles, grab objects and their vertices, reposition nodes, create GUIs, extract velocities and many more. All this is done with the help of the discussed data structures, e.g. scalars and lists. “If-else” conditions also play a very important role. They are always needed to branch to different parts of script, distinguish between certain states and to create the desired results.
A result from “Objects2Vertices” – one of the scripts discussed in this chapter.
The first scripts are mainly simple examples to give an idea of what is happening while the code is executed. In the beginning there are not always visible results in your viewport, just long lists of numbers in the Messages window. When you have to deal with scripting, this window will soon become a very close friend, because there you will find all the results, warnings and errors. Whenever you have to check the plausibility of your script’s calculations and results, there should be an output to the "Messages" window. The process of erasing errors is called debugging. RealFlow does not offer a complete visual programming environment, such as Visual C/C++, but has basic debugging functions with a specification of the affected line of code. Please remember that tabbing is a very important issue with Python. The indents and spaces in front of a line are not only for making your script more readable and more clearly arranged; they are also part of the syntax. You should always use the Tab key to create the indents, never the space bar. Scripts from external resources, in particular, might give you syntax errors because of wrongly input spaces. You should always check the indents.