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 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
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 we want to use from this library in this case everything. It is also possible to only select the parts you want to use by declaring the import as follows : "from Libraries.FlowFlexibleMeshFunctions import WaterFlowFMModel"

In the second line we create a variable named "fmModel" and assign a new "WaterFlowFMModel" instance to it. This is possible because the "FlowFlexibleMeshFunctions" library defined WaterFlowFMModel.

To run the script select the lines and press CTRL + ENTER. The fmModel variable will now contain an instance of a flow flexible mesh model. It is usually a good idea to run the  import command after you finished declaring it, 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 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
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 project. 

 

After running these lines you will be able to see the model in the project explorer (just like the image below)

scrollbar