@@ -788,7 +788,7 @@ def sendExpression(self, command, parsed=True):
788788
789789
790790class ModelicaSystem (object ):
791- def __init__ (self , fileName = None , modelName = None , lmodel = [], useCorba = False , commandLineOptions = None , variableFilter = None ): # 1
791+ def __init__ (self , fileName = None , modelName = None , lmodel = [], useCorba = False , commandLineOptions = None , variableFilter = None , verbose = True ): # 1
792792 """
793793 "constructor"
794794 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
860860
861861 if fileName is not None :
862862 self .loadFile ()
863+ self .loadLibrary (verbose )
863864
864865 ## allow directly loading models from MSL without fileName
865866 if fileName is None and modelName is not None :
866- self .loadLibrary ()
867+ self .loadLibrary (verbose )
867868
868- self .buildModel ()
869+ self .buildModel (variableFilter , verbose )
869870
870871 def __del__ (self ):
871872 OMCSessionBase .__del__ (self )
@@ -886,20 +887,25 @@ def loadFile(self):
886887 return print (self .getconn .sendExpression ("getErrorString()" ))
887888
888889 # for loading file/package, loading model and building model
889- def loadLibrary (self ):
890+ def loadLibrary (self , verbose ):
890891 # load Modelica standard libraries or Modelica files if needed
891892 for element in self .lmodel :
892893 if element is not None :
893- loadmodelError = ''
894894 if isinstance (element , str ):
895895 if element .endswith (".mo" ):
896896 loadModelResult = self .requestApi ("loadFile" , element )
897897 if not loadModelResult :
898898 loadmodelError = self .requestApi ('getErrorString' )
899+ ## always print the notification warning to user, to suppress the warnings add verbose=False
900+ if verbose :
901+ print (self .requestApi ('getErrorString' ))
899902 else :
900903 loadModelResult = self .requestApi ("loadModel" , element )
901904 if not loadModelResult :
902905 loadmodelError = self .requestApi ('getErrorString' )
906+ if verbose :
907+ print (self .requestApi ('getErrorString' ))
908+
903909 elif isinstance (element , tuple ):
904910 if not element [1 ]:
905911 libname = "" .join (["loadModel(" , element [0 ], ")" ])
@@ -908,10 +914,10 @@ def loadLibrary(self):
908914 loadModelResult = self .sendExpression (libname )
909915 if not loadModelResult :
910916 loadmodelError = self .sendExpression ("getErrorString()" )
917+ if verbose :
918+ print (self .requestApi ('getErrorString' ))
911919 else :
912920 print ("| info | loadLibrary() failed, Unknown type detected: " , element , " is of type " , type (element ), ", The following patterns are supported\n 1)[\" Modelica\" ]\n 2)[(\" Modelica\" ,\" 3.2.3\" ), \" PowerSystems\" ]\n " )
913- if loadmodelError :
914- print (loadmodelError )
915921
916922 def setTempDirectory (self ):
917923 # create a unique temp directory for each session and build the model in that directory
@@ -925,7 +931,7 @@ def setTempDirectory(self):
925931 def getWorkDirectory (self ):
926932 return self .tempdir
927933
928- def buildModel (self , variableFilter = None ):
934+ def buildModel (self , variableFilter = None , verbose = True ):
929935 if variableFilter is not None :
930936 self .variableFilter = variableFilter
931937
@@ -937,11 +943,14 @@ def buildModel(self, variableFilter=None):
937943 # buildModelResult=self.getconn.sendExpression("buildModel("+ mName +")")
938944 buildModelResult = self .requestApi ("buildModel" , self .modelName , properties = varFilter )
939945 buildModelError = self .requestApi ("getErrorString" )
946+
947+ if ('' in buildModelResult ):
948+ print (buildModelError )
949+
940950 # Issue #145. Always print the getErrorString since it might contains build warnings.
941- if buildModelError :
951+ if verbose :
942952 print (buildModelError )
943- if ('' in buildModelResult ):
944- return
953+
945954 self .xmlFile = os .path .join (os .path .dirname (buildModelResult [0 ]),buildModelResult [1 ]).replace ("\\ " ,"/" )
946955 self .xmlparse ()
947956
0 commit comments