Initializing a GUI

This chapter deals with the first step described above. To create a window, RealFlow needs a certain statement to initialize a new GUI window. All the other statements are always related to this instruction:

window = GUIFormDialog.new()

 

The type of window you will get with this instruction is what is known as amodal window. Modal windows always have the operating system’s focus. This means that it is not possible to access other windows, menus or functions of RealFlow as long as the GUI window is open. The next step is to define the appropriate data type. You can use as many input fields as you want, but adding a field obeys some basic rules, too. Each field requires two arguments: the field’s individual name and the default value. If the user does not want to make entries, RealFlow has to know which setting will be used for the following script.

These are the constructors for the different data types and input fields:

window.addIntField(string, int)
window.addFloatField(string, float)
window.addVectorField(string, float, float, float)
window.addStringField(string, string)
window.addBoolField(string, boolean)
window.addListField(string, string, int)

 

The common thing with all fields is the first string statement within the brackets. Here you can enter an arbitrary name that will be displayed in the GUI window. Most field definitions expect two arguments, but addVectorField requires four, the addListField three entries. The meaning of the vector field’s arguments should be pretty clear now, because a vector always consists of three floating numbers. With list fields it is a little bit different. The second string determines a predefined list variable with appropriate entries:

objects = [Sphere","Cube","Vase","Torus","Rocket"]

 

The corresponding list field could look like this

window.addListField("Object selection", objects, 2)

 

In this case, the field’s name is “Object selection” and in the GUI window you will see all the entries from object lists you have defined before. The object’s variable in the list field’s arguments is substituted by the elements of the objects list. The integer is the option that is selected by default and directly refers to the list’s order of elements. The default selection is “Vase” here, because lists always start with 0 and counting through the entries gives you 0 – Sphere, 1 – Cube, 2 – Vase, 3 – Torus, 4 – Rocket.

The first string variable is the field’s individual name, which must be unique, because RealFlow later identifies the entered values by using exactly the same name. A window definition like this is not valid:

window.addFloatField("Friction", 0.001)
window.addFloatField("Friction", 0.005)

 

A correct construction would be: 

window.addFloatField("Particle Friction", 0.001)
window.addFloatField("Object Friction", 0.005) 

 

A good example for the definition of a GUI window is a script-based creation of an emitter. You can write the following code to a batch script window:

window = GUIFormDialog.new()
 
emitter_types  = ["Circle","Square","Sphere","Linear","Cylinder"]
particle_types = ["Liquid","Dumb","Elastics"]

window.addListField("Emitter Type", emitter_types, 0)
window.addListField("Particle Type", particle_types, 0)
window.addFloatField("Resolution", 1.0)
window.addFloatField("Density", 1000.0)
window.addFloatField("Int Pressure", 1.0)
window.addFloatField("Ext Pressure", 1.0)
window.addFloatField("Viscosity", 3.0)
window.addFloatField("Surface Tension", 1.0)
window.addStringField("Name", "Emitter")

 

The fields represent the most important physical parameters of an emitter. If you have often-used settings, you can change the defaults to your needs, e.g. higher resolution:

window.addFloatField("Resolution", 5.0)
This is the first part of GUI creation, and so far the script does not work, because some important elements and definitions are still missing.