Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 11 additions & 20 deletions OMPython/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ def __init__(self, fileName=None, modelName=None, lmodel=[], useCorba=False, com
self.setTempDirectory()

if fileName is not None:
self.loadFile()
self.loadFile(verbose)
self.loadLibrary(verbose)

## allow directly loading models from MSL without fileName
Expand All @@ -879,11 +879,12 @@ def setCommandLineOptions(self):
if not cmdexp:
return print(self.getconn.sendExpression("getErrorString()"))

def loadFile(self):
def loadFile(self, verbose):
# load file
loadFileExp="".join(["loadFile(","\"",self.fileName,"\"",")"]).replace("\\","/")
loadMsg = self.getconn.sendExpression(loadFileExp)
if not loadMsg:
## Show notification or warnings to the user when verbose=True OR if some error occurred i.e., not result
if verbose or not loadMsg:
return print(self.getconn.sendExpression("getErrorString()"))

# for loading file/package, loading model and building model
Expand All @@ -893,31 +894,21 @@ def loadLibrary(self, verbose):
if element is not None:
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'))
apiCall = "loadFile"
else:
loadModelResult = self.requestApi("loadModel", element)
if not loadModelResult:
loadmodelError = self.requestApi('getErrorString')
if verbose:
print(self.requestApi('getErrorString'))

apiCall = "loadModel"
result = self.requestApi(apiCall, element)
elif isinstance(element, tuple):
if not element[1]:
libname = "".join(["loadModel(", element[0], ")"])
else:
libname = "".join(["loadModel(", element[0], ", ", "{", "\"", element[1], "\"", "}", ")"])
loadModelResult = self.sendExpression(libname)
if not loadModelResult:
loadmodelError = self.sendExpression("getErrorString()")
if verbose:
print(self.requestApi('getErrorString'))
result = self.sendExpression(libname)
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")
## Show notification or warnings to the user when verbose=True OR if some error occurred i.e., not result
if verbose or not result:
print(self.requestApi('getErrorString'))

def setTempDirectory(self):
# create a unique temp directory for each session and build the model in that directory
Expand Down