Package: pyofw
pyofwPython package for OpenFlowsWater module from Bentley that mainly contains the stub (*.pyi) files and a few py files to get started.Must Create python.exe.config File [NOTneeded for 10.4 or higher]Bentley's WaterObjects.NET API contains a mixed mode (managed/unmanaged)
assemblies as a result, a python configuration file has to placed where the python.exe is location (in your environment). The contents of the file can be copied from below or use fromhere.Note:Filename is important. For "python.exe" create "python.exe.config"<?xml version="1.0"?><configuration><startupuseLegacyV2RuntimeActivationPolicy="true"><supportedRuntimeversion="v4.0"sku=".NETFramework,Version=v4.0"/></startup></configuration>InstallationRun the following to install:pipinstallpyofwFailed to install?One of the requirements package ispythonnetwhich might not get installed directly. In such case, follow the stepshow to install pythonnet.Note:The package itself will not add any value without theBentley'sOpenFlows application likeWaterGEMS, orWaterCAD. And the package assumes the application is installed at the default location. For WaterGEMS it isC:\Program Files (x86)\Bentley\WaterGEMS\x64.Usage# -------------------- VERY FIRST STEP ---------------------# | Navigate to the folder where you are about to create your *.py files# | In this folder/workspace, bring up the console/terminal and run:# | newofw# | --------------------------------------------------------# | Above command will add "typings" folder to the workspace# | then ONLY the IntelliSense will work# | --------------------------------------------------------frompyofw.configimportOFWConfigconfig=OFWConfig()# by default, prepare things for WaterGEMSmodel=config.open_model(r"C:\Program Files (x86)\Bentley\WaterGEMS\Samples\Example5.wtg")print(f"Active scenario is:{model.ActiveScenario.Label}")print(f"And there are '{model.Scenarios.Count}' scenarios in the '{model}' model")config.end_session()# close the model and end the session'newofw' command is showing error?Are you getting errors like below?newofw : The term 'newofw' is not recognized as the name of a cmdlet'newofw' is not recognized as an internal or external commandThis could be possible depending on how python is installed. To troubleshoot, make sure you are using the right python.exe.Find out where the python.exe is. Runwhere pythonin the console. This will display the full path of the python.exe.NoteThewhere pythoncommand will not give any results in PowerShell terminal. In PowerShell, the command isGet-Command python.D:\SDK\python\3_10\python.exeModify the path like the below:D:\SDK\python\3_10\Scripts\newofw.exeCheck if the above filenewofw.exeexists.DoesNOTexists: reinstall the module again by runningpython -m pip install pyofwExits: run the exe from the command line. Make sure to be in the right directory.D:\My\Correct\Folder>D:\SDK\python\3_10\Scripts\newofw.exeIntelliSense not working?For IntelliSense to work properly, we have to make sure certain settings are configured properly.VSCode IDEIf VSCode is the IDE of choice,PressCtrl+Shift+Pand type inSettings.SelectPreferences: Open User[/Workspace] Settings, which will open up the Settings.In the search type,stubEither on User or Workspace tab, selectpylanceUnderPython • Analysis: Stub Path, make suretypingsis selectedHow to install pythonnet?pythonnetmay not get installed bypip install pythonnetas a result follow this alternative.Common Error messageERROR: Could not build wheels for pythonnet which use PEP 517 and cannot be installed directlySteps to install pythonnetDownload the wheel file fromhttps://www.lfd.uci.edu/~gohlke/pythonlibs/#pythonnetFor 3.9 version of python, on windows, downloadpythonnet-2.5.2-cp39-cp39-win_amd64.whl.runpip install "path\to\the\downloaded\pythonnet.whl"Test if pythonnet got installed. Ifimport clrdoesn't return any error thenpythonnetis ready to usec:\>pythonPython3.9.2(tags/v3.9.2:1a79785,Feb192021,13:44:55)[MSCv.192864bit(AMD64)]onwin32Type"help","copyright","credits"or"license"formoreinformation.>>>importclr>>>ERROR at Run Time?clr ERRORAttributeError: module 'clr' has no attribute 'AddReference'error that most likely due the installed package calledclr. Simply uninstall this package and the error should go away.pip uninstall clrNo module named 'OpenFlows'ModuleNotFoundError: No module named 'OpenFlows'Make sure the OpenFlows*.dll files are in the x64 directory of the Water products
You could also pass in the custom locationofw_config = OpenFlowsWaterConfig(dlls_dir="C:\Path\To\WaterGEMS\x64")More Examplespy FilesVery minimal with no comments:Example_Minimal[Recommended]Good example to get started:Example_with_commentsExample with minimal uses ofpyofwmodule:Similar to .NETJupyter Notebook (DataFrames for Elements)For more details, navigate toNetwork Input Notebookfrompyofw.network_inputimportNetworkInputni:NetworkInput=NetworkInput(model)# Linksni.pipe_df.head(2)ni.lateral_df.head(2)# Nodesni.junction_df.head(2)ni.hydrant_df.head(2)ni.tank_df.head(2)ni.reservoir_df.head(2)ni.tap_df.head(2)ni.pump_df.head(2)ni.customer_meter_df.head(2)ni.scada_elem_df.head(2)ni.pump_stn_df.head(2)ni.vspb_df.head(2)ni.prv_df.head(2)ni.psv_df.head(2)ni.pbv_df.head(2)ni.fcv_df.head(2)ni.tcv_df.head(2)ni.pbv_df.head(2)ni.iso_valve_df.head(2)ni.hydro_tank_df.head(2)ni.check_valve_df.head(2)Jupyter Notebook Showing ResultsPlease navigate to:Getting_Started.
This notebook also shows some charts usingplotlylibrary. A few of Images..Tank Level and Pump Flows (using secondary axis)Tank Level and Pump Flows (just like in WaterGEMS)Network display (using networkx module)