Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

OpenModelica OMPython example model throws load file error

OpenModelica OMPython example model throws load file error

code:

import numpy as np
from matplotlib import pyplot as plt
import pyfmi
from OMPython import OMCSessionZMQ
from OMPython import ModelicaSystem

omc = OMCSessionZMQ()

model_path = '/usr/lib/omlibrary/Modelica 3.2.3/Electrical/'

omc.sendExpression('loadModel(model_path + Machines.mo)')

mod = ModelicaSystem(model_path + 'Machines.mo','Modelica.Electrical.Machines.Examples.AsynchronousInductionMachines.AIMC_Inverter')


error:

loadFile Error: Error: Failed to insert class Machines within Modelica.Electrical;

the available classes were:

Re: OpenModelica OMPython example model throws load file error

You always load the full Modelica library via loadModel(Modelica), you cannot load parts of it.

Seems the ModelicaSystem interface needs a file as the first argument, that is weird, it should not be need in some cases.
You can just do like this:

Code:


model_path = omc.sendExpression("getInstallationDirectoryPath()") + "/share/doc/omc/testmodels/"
mod = ModelicaSystem(model_path + "HelloWorld.mo","Modelica.Electrical.Machines.Examples.AsynchronousInductionMachines.AIMC_Inverter",["Modelica"]);

Basically load HelloWorld.mo but don't use it and also request Modelica library to be loaded (3rd argument).

Re: OpenModelica OMPython example model throws load file error

Thank you so much!

Now it works just fine!

There are 0 guests and 0 other users also viewing this topic
You are here: