@@ -788,7 +788,7 @@ def sendExpression(self, command, parsed=True):
788
788
789
789
790
790
class 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
792
792
"""
793
793
"constructor"
794
794
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
860
860
861
861
if fileName is not None :
862
862
self .loadFile ()
863
+ self .loadLibrary (verbose )
863
864
864
865
## allow directly loading models from MSL without fileName
865
866
if fileName is None and modelName is not None :
866
- self .loadLibrary ()
867
+ self .loadLibrary (verbose )
867
868
868
- self .buildModel ()
869
+ self .buildModel (variableFilter , verbose )
869
870
870
871
def __del__ (self ):
871
872
OMCSessionBase .__del__ (self )
@@ -886,20 +887,25 @@ def loadFile(self):
886
887
return print (self .getconn .sendExpression ("getErrorString()" ))
887
888
888
889
# for loading file/package, loading model and building model
889
- def loadLibrary (self ):
890
+ def loadLibrary (self , verbose ):
890
891
# load Modelica standard libraries or Modelica files if needed
891
892
for element in self .lmodel :
892
893
if element is not None :
893
- loadmodelError = ''
894
894
if isinstance (element , str ):
895
895
if element .endswith (".mo" ):
896
896
loadModelResult = self .requestApi ("loadFile" , element )
897
897
if not loadModelResult :
898
898
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' ))
899
902
else :
900
903
loadModelResult = self .requestApi ("loadModel" , element )
901
904
if not loadModelResult :
902
905
loadmodelError = self .requestApi ('getErrorString' )
906
+ if verbose :
907
+ print (self .requestApi ('getErrorString' ))
908
+
903
909
elif isinstance (element , tuple ):
904
910
if not element [1 ]:
905
911
libname = "" .join (["loadModel(" , element [0 ], ")" ])
@@ -908,10 +914,10 @@ def loadLibrary(self):
908
914
loadModelResult = self .sendExpression (libname )
909
915
if not loadModelResult :
910
916
loadmodelError = self .sendExpression ("getErrorString()" )
917
+ if verbose :
918
+ print (self .requestApi ('getErrorString' ))
911
919
else :
912
920
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 )
915
921
916
922
def setTempDirectory (self ):
917
923
# create a unique temp directory for each session and build the model in that directory
@@ -925,7 +931,7 @@ def setTempDirectory(self):
925
931
def getWorkDirectory (self ):
926
932
return self .tempdir
927
933
928
- def buildModel (self , variableFilter = None ):
934
+ def buildModel (self , variableFilter = None , verbose = True ):
929
935
if variableFilter is not None :
930
936
self .variableFilter = variableFilter
931
937
@@ -937,11 +943,14 @@ def buildModel(self, variableFilter=None):
937
943
# buildModelResult=self.getconn.sendExpression("buildModel("+ mName +")")
938
944
buildModelResult = self .requestApi ("buildModel" , self .modelName , properties = varFilter )
939
945
buildModelError = self .requestApi ("getErrorString" )
946
+
947
+ if ('' in buildModelResult ):
948
+ print (buildModelError )
949
+
940
950
# Issue #145. Always print the getErrorString since it might contains build warnings.
941
- if buildModelError :
951
+ if verbose :
942
952
print (buildModelError )
943
- if ('' in buildModelResult ):
944
- return
953
+
945
954
self .xmlFile = os .path .join (os .path .dirname (buildModelResult [0 ]),buildModelResult [1 ]).replace ("\\ " ,"/" )
946
955
self .xmlparse ()
947
956
0 commit comments