These are some steps to get orcaflex and conda to work together. By default they don’t, but with some hacking you can get it to function.
Note that this is in no way endorsed or supported by Orcina. It is merely a friendly hack (into your computer, not into orcaflex) to get this to work.
So why would you want to use conda? In my case I want to have separate environments for the different kind of work that I do and some of the packages (wavespectra.SpecDataset.to_orcaflex — wavespectra 3.11.0 documentation) can only be installed from conda if you do not have a compiler installed (which many corporate machines do not)
Installing the orcaflex API
There are two ways to do this. Either via the batch file included with orcaflex or directly from pip
Via the batch file
Activate the conda environment that you want the API to be installed in
Copy the OrcFxAPI/Python folder to a temporary location (we need write access)
python setup.py install --force
Run
This should install the OrcFxAPI package into the currently active conda environment.
If all goes well than you should now be able to import OrcFxAPI into the current environment:
Installing the orcaflex API with PIP
Not tested, but a plain
pip install OrcFxAPI
may also work, see OrcFxAPI · PyPI
Running python External Functions
For Orcaflex 11.2 and lower getting orcaflex external functions to work in combination with conda requires some hacking.
To be able to run external python functions from orcaflex, orcaflex needs to know where to find the conda environment that you installed the OrcFxAPI to. Also, this should be the only (or at least the first) interpreter that orcaflex find.
This information is obtained from the registry. Orcaflex looks under the HKEY_CURRENT_USER\SOFTWARE\Python\PythonCore branch for suitable python distributions. So all we need to do is to add a reference to our conda environment.
What we need to do is to OVERWRITE the existing PythonCore entry to point to the environment that the API is installed into. Note that this may break other software.
- Copy the text below into a text file,
- change the part “C:\python\miniconda3\envs\work” to the location where your conda environment is located,
- change the python version (3.9) to the python version that you are using
- save the file using the .reg extension
- double-click that file to add the information to the registry.
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\SOFTWARE\Python\PythonCore]
[HKEY_CURRENT_USER\SOFTWARE\Python\PythonCore\3.9]
[HKEY_CURRENT_USER\SOFTWARE\Python\PythonCore\3.9\InstallPath]
@="C:\python\miniconda3\envs\work"
[HKEY_CURRENT_USER\SOFTWARE\Python\PythonCore\3.9\PythonPath]
@="C:\python\miniconda3\envs\work\Lib;C:\python\miniconda3\envs\work\DLLs"
Now start orcaflex from within the activated conda environment. This is easiest done from the command prompt.
Debugging External Functions using the python debugger
It is possible to use break-points in external functions. This can be a great help when debugging.
The trick to get this to work is to run the orcaflex model from a python interpreter with the debugger attached instead of from the GUI:
import OrcFxAPI as ofx model = ofx.Model(r"C:\data\temp\ExternalFunctionExamples\Python\DynamicPositioningSystem.dat") model.RunSimulation()
Steps:
- Create a python script to run the orcaflex model (see example below)
- Open the external function file in the same project (using PyCharm, expect to be similar in other editors)
- Add a breakpoint to the external function file
- Run the main script in debugging mode
Result: