Skip to content

Commit c459f6a

Browse files
committed
[ModelicaSystem] update plot() function - include checks
* check if OMCProcessLocal is used * check for available resultfile
1 parent 78c6198 commit c459f6a

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,21 +1135,28 @@ def simulate(
11351135
def plot(
11361136
self,
11371137
plotdata: str,
1138-
resultfile: Optional[str] = None,
1138+
resultfile: Optional[str | os.PathLike] = None,
11391139
) -> None:
11401140
"""
1141-
Plot via OMC.
1141+
Plot a variable using OMC; this will work for local OMC usage only (OMCProcessLocal).
11421142
"""
11431143

1144-
if resultfile is None:
1145-
# default result file generated by OM
1146-
plot_result_file = self.getWorkDirectory() / f"{self._model_name}_res.mat"
1147-
elif os.path.exists(resultfile):
1144+
if not isinstance(self._getconn.omc_process, OMCProcessLocal):
1145+
raise ModelicaSystemError("Plot is using the OMC plot functionality; "
1146+
"thus, it is only working if OMC is running locally!")
1147+
1148+
plot_result_file = None
1149+
if resultfile is not None:
11481150
plot_result_file = pathlib.Path(resultfile)
1151+
elif self._result_file is not None:
1152+
plot_result_file = pathlib.Path(self._result_file)
11491153
else:
11501154
ModelicaSystemError("No resultfile available - either run simulate() before plotting "
11511155
"or provide a result file!")
11521156

1157+
if not plot_result_file.is_file():
1158+
ModelicaSystemError(f"Provided resultfile {repr(plot_result_file.as_posix())} does not exists!")
1159+
11531160
expr = f'plot({plotdata}, fileName="{plot_result_file.as_posix()}")'
11541161

11551162
self.sendExpression(expr=expr)

0 commit comments

Comments
 (0)