diff --git a/epyt/epanet.py b/epyt/epanet.py index e8fe012..d279920 100644 --- a/epyt/epanet.py +++ b/epyt/epanet.py @@ -510,8 +510,9 @@ class epanet: d = epanet(inpname, msx=True,customlib=epanetlib) """ - def __init__(self, *argv, version=2.2, ph=False, loadfile=False, customlib=None): + def __init__(self, *argv, version=2.2, ph=False, loadfile=False, customlib=None, display_msg=True): # Constants + self.msx = None warnings.simplefilter('always') # Demand model types. DDA #0 Demand driven analysis, # PDA #1 Pressure driven analysis. @@ -573,8 +574,10 @@ def __init__(self, *argv, version=2.2, ph=False, loadfile=False, customlib=None) # Initial attributes self.classversion = __version__ self.api = epanetapi(version, ph=ph, customlib=customlib) - print(f'EPANET version {self.getVersion()} ' - f'loaded (EPyT version {self.classversion}).') + self.display_msg = display_msg + if self.display_msg: + print(f'EPANET version {self.getVersion()} ' + f'loaded (EPyT version {self.classversion}).') # ToolkitConstants: Contains all parameters from epanet2_2.h self.ToolkitConstants = ToolkitConstants() @@ -632,7 +635,8 @@ def __init__(self, *argv, version=2.2, ph=False, loadfile=False, customlib=None) self.netName = os.path.basename(self.InputFile) self.LibEPANETpath = self.api.LibEPANETpath self.LibEPANET = self.api.LibEPANET - print(f'Input File {self.netName} loaded successfully.\n') + if self.display_msg: + print(f'Input File {self.netName} loaded successfully.\n') # Global plot settings plt.rcParams["figure.figsize"] = [3, 2] @@ -3697,7 +3701,7 @@ def getLinkVertices(self, *argv): continue x_mat = [] y_mat = [] - for j in range(1, self.getLinkVerticesCount(i) +1): + for j in range(1, self.getLinkVerticesCount(i) + 1): xy = self.api.ENgetvertex(i, j) x_mat.append(xy[0]) y_mat.append(xy[1]) @@ -10394,7 +10398,9 @@ def unload(self): safe_delete(file) except: pass - print(f'Close toolkit for the input file "{self.netName[0:-4]}". EPANET Toolkit is unloaded.\n') + if self.display_msg: + print(f'Close toolkit for the input file "{self.netName[0:-4]}". EPANET Toolkit is ' + f'unloaded.\n') def useHydraulicFile(self, hydname): """ Uses the contents of the specified file as the current binary hydraulics file. @@ -11185,8 +11191,8 @@ def loadMSXFile(self, msxname, customMSXlib=None, ignore_properties=False): Example using custom msx library : msxlib=os.path.join(os.getcwd(), 'epyt','libraries','win','epanetmsx.dll') - d = epanet(inpname, msx=True,customlib=epanetlib) - d.loadMSXFile(msxname,customMSXlib=msxlib)""" + d = epanet(inpname, msx=True, customlib=epanetlib) + d.loadMSXFile(msxname, customMSXlib=msxlib)""" if not os.path.exists(msxname): for root, dirs, files in os.walk(resource_filename("epyt", "")): @@ -11203,16 +11209,10 @@ def loadMSXFile(self, msxname, customMSXlib=None, ignore_properties=False): copyfile(msxname, self.msxname) self.msx = epanetmsxapi(self.msxname, customMSXlib=customMSXlib) + # Message to user if he uses ph with msx + if self.api.ph is not None: + warnings.warn('Please set ph=False when using MSX.') - - - - #message to user if he uses ph with msx - if self.api._ph is not None: - print("In order for LoadMSX to work remove from epanet the ph") - print("Example: change this line ") - print("from this: <<