Skip to content

Commit 3832aba

Browse files
committed
Add session kwarg to ModelicaSystem constructor
If the session kwarg is specified, the ModelicaSystem will use that session instead of creating a new one. This is useful for creating a ModelicaSystem for a model that is already loaded in an already existing session.
1 parent 5368216 commit 3832aba

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

OMPython/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ class ModelicaSystem(object):
821821
def __init__(self, fileName=None, modelName=None, lmodel=None,
822822
useCorba=False, commandLineOptions=None,
823823
variableFilter=None, customBuildDirectory=None, verbose=True, raiseerrors=False,
824-
omhome: str = None): # 1
824+
omhome: str = None, session: OMCSessionBase = None): # 1
825825
"""
826826
"constructor"
827827
It initializes to load file and build a model, generating object, exe, xml, mat, and json files. etc. It can be called :
@@ -857,10 +857,13 @@ def __init__(self, fileName=None, modelName=None, lmodel=None,
857857

858858
self._verbose = verbose
859859

860-
if useCorba:
861-
self.getconn = OMCSession(omhome=omhome)
860+
if session is not None:
861+
self.getconn = session
862862
else:
863-
self.getconn = OMCSessionZMQ(omhome=omhome)
863+
if useCorba:
864+
self.getconn = OMCSession(omhome=omhome)
865+
else:
866+
self.getconn = OMCSessionZMQ(omhome=omhome)
864867

865868
## needed for properly deleting the OMCSessionZMQ
866869
self._omc_log_file = self.getconn._omc_log_file

0 commit comments

Comments
 (0)