diff --git a/OMPython/__init__.py b/OMPython/__init__.py index 46894c1..c075b4b 100755 --- a/OMPython/__init__.py +++ b/OMPython/__init__.py @@ -788,7 +788,7 @@ def sendExpression(self, command, parsed=True): class ModelicaSystem(object): - def __init__(self, fileName=None, modelName=None, lmodel=[], useCorba=False, commandLineOptions=None, variableFilter=None): # 1 + def __init__(self, fileName=None, modelName=None, lmodel=[], useCorba=False, commandLineOptions=None, variableFilter=None, verbose=True): # 1 """ "constructor" It initializes to load file and build a model, generating object, exe, xml, mat, and json files. etc. It can be called : @@ -860,12 +860,13 @@ def __init__(self, fileName=None, modelName=None, lmodel=[], useCorba=False, com if fileName is not None: self.loadFile() + self.loadLibrary(verbose) ## allow directly loading models from MSL without fileName if fileName is None and modelName is not None: - self.loadLibrary() + self.loadLibrary(verbose) - self.buildModel() + self.buildModel(variableFilter, verbose) def __del__(self): OMCSessionBase.__del__(self) @@ -886,20 +887,25 @@ def loadFile(self): return print(self.getconn.sendExpression("getErrorString()")) # for loading file/package, loading model and building model - def loadLibrary(self): + def loadLibrary(self, verbose): # load Modelica standard libraries or Modelica files if needed for element in self.lmodel: if element is not None: - loadmodelError = '' if isinstance(element, str): if element.endswith(".mo"): loadModelResult = self.requestApi("loadFile", element) if not loadModelResult: loadmodelError = self.requestApi('getErrorString') + ## always print the notification warning to user, to suppress the warnings add verbose=False + if verbose: + print(self.requestApi('getErrorString')) else: loadModelResult = self.requestApi("loadModel", element) if not loadModelResult: loadmodelError = self.requestApi('getErrorString') + if verbose: + print(self.requestApi('getErrorString')) + elif isinstance(element, tuple): if not element[1]: libname = "".join(["loadModel(", element[0], ")"]) @@ -908,10 +914,10 @@ def loadLibrary(self): loadModelResult = self.sendExpression(libname) if not loadModelResult: loadmodelError = self.sendExpression("getErrorString()") + if verbose: + print(self.requestApi('getErrorString')) else: print("| info | loadLibrary() failed, Unknown type detected: ", element , " is of type ", type(element), ", The following patterns are supported\n1)[\"Modelica\"]\n2)[(\"Modelica\",\"3.2.3\"), \"PowerSystems\"]\n") - if loadmodelError: - print(loadmodelError) def setTempDirectory(self): # create a unique temp directory for each session and build the model in that directory @@ -925,7 +931,7 @@ def setTempDirectory(self): def getWorkDirectory(self): return self.tempdir - def buildModel(self, variableFilter=None): + def buildModel(self, variableFilter=None, verbose=True): if variableFilter is not None: self.variableFilter = variableFilter @@ -937,11 +943,14 @@ def buildModel(self, variableFilter=None): # buildModelResult=self.getconn.sendExpression("buildModel("+ mName +")") buildModelResult = self.requestApi("buildModel", self.modelName, properties=varFilter) buildModelError = self.requestApi("getErrorString") + + if ('' in buildModelResult): + print(buildModelError) + # Issue #145. Always print the getErrorString since it might contains build warnings. - if buildModelError: + if verbose: print(buildModelError) - if ('' in buildModelResult): - return + self.xmlFile=os.path.join(os.path.dirname(buildModelResult[0]),buildModelResult[1]).replace("\\","/") self.xmlparse() diff --git a/setup.py b/setup.py index 5a23e44..77077d8 100755 --- a/setup.py +++ b/setup.py @@ -54,7 +54,7 @@ def generateIDL(): OMPython_packages.extend(['OMPythonIDL', 'OMPythonIDL._OMCIDL', 'OMPythonIDL._OMCIDL__POA']) setup(name='OMPython', - version='3.5.0', + version='3.5.1', description='OpenModelica-Python API Interface', author='Anand Kalaiarasi Ganeson', author_email='ganan642@student.liu.se',