Skip to content

ModelicaSystem cannot load model from relative path #245

Closed

Description

@ondras12345

Description

The documentation says that

Note: If the model file is not in the current working directory, then the path where file is located must be included together with file name. Besides, if the Modelica model contains several different models within the same package, then in order to build the specific model, in second argument, user must put the package name with dot(.) followed by specific model name.

However, this doesn't work in practice:

$ cd /usr/share/doc/omc/testmodels 
$ ipython3                                   
/usr/lib/python3/dist-packages/IPython/core/interactiveshell.py:915: UserWarning: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv.
  warn(
Python 3.12.3 (main, Feb  4 2025, 14:48:35) [GCC 13.3.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.20.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from OMPython import ModelicaSystem

In [2]: mod = ModelicaSystem("BouncingBall.mo", "BouncingBall")
2025-04-07 11:31:12,386 - OMPython - ERROR - Error: Failed to load package BouncingBall (default) using MODELICAPATH /home/ondra/.openmodelica/libraries/.
Error: Class BouncingBall not found in scope <top>.

2025-04-07 11:31:12,386 - OMPython - ERROR - XML file not generated: 

In [3]: from pathlib import Path

In [4]: mod = ModelicaSystem(str(Path("BouncingBall.mo").resolve()), "BouncingBall")

In [5]: 

Version and OS

  • Python Version: 3.12.3
  • OMPython Version: 5904e4e
  • OpenModelica Version: 1.25.0
  • OS: Ubuntu 24.04.2 LTS

Additional Context

I think I'll try to fix this myself and submit a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions