Skip to content

Commit 8e8c056

Browse files
committed
Merge branch 'ModelicaSystem_check' into MERGE-4.1.0.rc2
2 parents ebc4a48 + a1500ab commit 8e8c056

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
OMCSessionRunData,
5353
OMCSessionZMQ,
5454
OMCProcess,
55+
OMCProcessLocal,
5556
OMCPath,
5657
)
5758

@@ -1141,6 +1142,36 @@ def simulate(
11411142

11421143
self._simulated = True
11431144

1145+
def plot(
1146+
self,
1147+
plotdata: str,
1148+
resultfile: Optional[str | os.PathLike] = None,
1149+
) -> None:
1150+
"""
1151+
Plot a variable using OMC; this will work for local OMC usage only (OMCProcessLocal).
1152+
"""
1153+
1154+
if not isinstance(self._session.omc_process, OMCProcessLocal):
1155+
raise ModelicaSystemError("Plot is using the OMC plot functionality; "
1156+
"thus, it is only working if OMC is running locally!")
1157+
1158+
plot_result_file = None
1159+
if resultfile is not None:
1160+
plot_result_file = self._session.omcpath(resultfile)
1161+
elif self._result_file is not None:
1162+
plot_result_file = self._session.omcpath(self._result_file)
1163+
else:
1164+
ModelicaSystemError("No resultfile available - either run simulate() before plotting "
1165+
"or provide a result file!")
1166+
1167+
if plot_result_file is None:
1168+
ModelicaSystemError("No resultfile defined!")
1169+
elif not plot_result_file.is_file():
1170+
ModelicaSystemError(f"Provided resultfile {repr(plot_result_file.as_posix())} does not exists!")
1171+
else:
1172+
expr = f'plot({plotdata}, fileName="{plot_result_file.as_posix()}")'
1173+
self.sendExpression(expr=expr)
1174+
11441175
def getSolutions(
11451176
self,
11461177
varList: Optional[str | list[str]] = None,

0 commit comments

Comments
 (0)