Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

scrollbar

We start by creating a script. In the toolbox tool window on the right, click on the scripting folder ("scripts" ) and select "Add new script". This will add a new script (with the name you provided) to your "scripts" folder and

open

opens the scripting editor (see Scripting editor overview for more details on the editor). 

To create a new flow flexible mesh model we start by adding the following lines:

Code Block
languagepy
titleCreating a new FM model
firstline1linenumbers
true
from Libraries.FlowFlexibleMeshFunctions import *

fmModel = WaterFlowFMModel()

In the first line we declare that we want to use a library. The first part "from Libraries.FlowFlexibleMeshFunctions" specifies where the library is located. In this case, it is located in the Libraries folder (under the scripting folder "scripts") in the file FlowFlexibleMeshFunctions.py. The second part, "import *"

declares what part

, indicates which functionalities we want to use from this library. An asterisk, in this case

everything

, means that all the functionalities contained in the file will be available after importing it. It is also possible to select only

select the parts you want to use by declaring the import as follows

some parts using a comma separated list. For example, if you only wanted to use the function WaterFlowFMModel, you could use: "from Libraries.FlowFlexibleMeshFunctions import WaterFlowFMModel".

In the

The second line

we create a variable named "fmModel" and assign

assigns a new

"

WaterFlowFMModel

"

object instance to

it. This is possible because the "FlowFlexibleMeshFunctions" library defined WaterFlowFMModel

the variable fmModel. The FlowFlexibleMeshFunctions library defines how a WaterFlowFMModel object must be constructed.

To run the script select the lines and press

Ctrl

CTRL +

Enter

ENTER. The variable fmModel

variable

will

now

then contain an instance of a flow flexible mesh model object. It is usually a good idea to run

the 

the import command after you

finished declaring

type it in, because this will add the functions and types to the code completion. This will make it easier to create the next lines of code

, and

. It will also provide documentation for the functions and types.

 

You will be able to view the model by adding the following lines :

Code Block
languagepy
titleAdding the model to the project
firstline1linenumberstrue
from Libraries.StandardFunctions import *

AddToProject(fmModel)

The first (import ..) line adds all the functions from the StandardFunctions library.  The second line adds the model in the fmModel variable to the current project.

 

 

After running these lines

you

, the model will be

able to see the model

placed in the project explorer

(just like the image below)

:

Image Modified

scrollbar