diff --git a/OMPython/ModelicaSystem.py b/OMPython/ModelicaSystem.py index 03c24b51..96c75224 100644 --- a/OMPython/ModelicaSystem.py +++ b/OMPython/ModelicaSystem.py @@ -352,7 +352,7 @@ def __init__( self._session = OMCSessionLocal(omhome=omhome) # get OpenModelica version - version_str = self.sendExpression(expr="getVersion()") + version_str = self._session.get_version() self._version = self._parse_om_version(version=version_str) # set commandLineOptions using default values or the user defined list if command_line_options is None: @@ -514,8 +514,7 @@ def setWorkDirectory(self, work_directory: Optional[str | os.PathLike] = None) - raise IOError(f"{workdir} could not be created") logger.info("Define work dir as %s", workdir) - expr = f'cd("{workdir.as_posix()}")' - self.sendExpression(expr=expr) + self._session.set_workdir(workdir=workdir) # set the class variable _work_dir ... self._work_dir = workdir diff --git a/OMPython/OMCSession.py b/OMPython/OMCSession.py index 6b5b2b3d..67fb1af2 100644 --- a/OMPython/OMCSession.py +++ b/OMPython/OMCSession.py @@ -766,6 +766,19 @@ def escape_str(value: str) -> str: """ return value.replace("\\", "\\\\").replace('"', '\\"') + def get_version(self) -> str: + """ + Get the OM version. + """ + return self.sendExpression("getVersion()", parsed=True) + + def set_workdir(self, workdir: OMCPath) -> None: + """ + Set the workdir for this session. + """ + exp = f'cd("{workdir.as_posix()}")' + self.sendExpression(exp) + def omcpath(self, *path) -> OMCPath: """ Create an OMCPath object based on the given path segments and the current OMCSession* class.