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

List Class Variable Names, Types, or Annotation

List Class Variable Names, Types, or Annotation

Is it possible via OMShell (or via OMPython) to get a listing of the variables in a class with the type and variable name or get the annotation on a variable?

I see the list(<type>) command; but parsing that doesn't seem trivial.

Re: List Class Variable Names, Types, or Annotation

What you want is:

Code:

getComponents(Some.ModelicalPath.Here);

or

Code:

getElements(Modelica.Blocks.Examples.PID_Controller, useQuotes = true);

{{"co", "-", "Modelica.SIunits.Angle", "driveAngle", "Reference distance to move", "public", "false", "false", "false", "false", "parameter", "none", "unspecified", "$Any", "{}"},{"co", "-", "Modelica.Blocks.Continuous.LimPID", "PI", "", "public", "false", "false", "false", "false", "unspecified", "none", "unspecified", "$Any", "{}"},{"co", "-", "Modelica.Mechanics.Rotational.Components.Inertia", "inertia1", "", "public", "false", "false", "false", "false", "unspecified", "none", "unspecified", "$Any", "{}"},{"co", "-", "Modelica.Mechanics.Rotational.Sources.Torque", "torque", "", "public", "false", "false", "false", "false", "unspecified", "none", "unspecified", "$Any", "{}"},{"co", "-", "Modelica.Mechanics.Rotational.Components.SpringDamper", "spring", "", "public", "false", "false", "false", "false", "unspecified", "none", "unspecified", "$Any", "{}"},{"co", "-", "Modelica.Mechanics.Rotational.Components.Inertia", "inertia2", "", "public", "false", "false", "false", "false", "unspecified", "none", "unspecified", "$Any", "{}"},{"co", "-", "Modelica.Blocks.Sources.KinematicPTP", "kinematicPTP", "", "public", "false", "false", "false", "false", "unspecified", "none", "unspecified", "$Any", "{}"},{"co", "-", "Modelica.Blocks.Continuous.Integrator", "integrator", "", "public", "false", "false", "false", "false", "unspecified", "none", "unspecified", "$Any", "{}"},{"co", "-", "Modelica.Mechanics.Rotational.Sensors.SpeedSensor", "speedSensor", "", "public", "false", "false", "false", "false", "unspecified", "none", "unspecified", "$Any", "{}"},{"co", "-", "Modelica.Mechanics.Rotational.Sources.ConstantTorque", "loadTorque", "", "public", "false", "false", "false", "false", "unspecified", "none", "unspecified", "$Any", "{}"}}

To see what this all means you can look at how we parse it.
This is how we parse the result of getComponents:
https://github.com/OpenModelica/OpenMod … t.cpp#L156
This is how we parse the result of getElements:
https://github.com/OpenModelica/OpenMod … t.cpp#L249

For Icon or Diagram annotations use getIconAnnotation and getDiagramAnnotation.

For any other annotations use:

Code:

getComponentAnnotations(Modelica.Blocks.Examples.PID_Controller);

Code:

getElementAnnotations(Modelica.Blocks.Examples.PID_Controller);

{{},{Placement(true,-,-,-56.0,-20.0,-36.0,0.0,-,-,-,-,-,-,-,)},{Placement(true,-,-,2.0,-20.0,22.0,0.0,-,-,-,-,-,-,-,)},{Placement(true,-,-,-25.0,-20.0,-5.0,0.0,-,-,-,-,-,-,-,)},{Placement(true,-,-,32.0,-20.0,52.0,0.0,-,-,-,-,-,-,-,)},{Placement(true,-,-,60.0,-20.0,80.0,0.0,-,-,-,-,-,-,-,)},{Placement(true,-,-,-92.0,20.0,-72.0,40.0,-,-,-,-,-,-,-,)},{Placement(true,-,-,-63.0,20.0,-43.0,40.0,-,-,-,-,-,-,-,)},{Placement(true,-,-,22.0,-50.0,2.0,-30.0,-,-,-,-,-,-,-,)},{Placement(true,-,-,98.0,-15.0,88.0,-5.0,-,-,-,-,-,-,-,)}}

See in Windows: %TMP%\OpenModelica\OMEdit\omeditcommunication.log what kind of API calls you can make. In Linux is /tmp/user/OpenModelica/....
Some of them ar documented here:
https://build.openmodelica.org/Document … pting.html

Good luck!

Re: List Class Variable Names, Types, or Annotation

Thank-you! This is precisely what we needed. Knowing OMEdit has that log will be very helpful to see what other API endpoints are available.

What is the difference in meaning of elements vs components?

Re: List Class Variable Names, Types, or Annotation

For getElements you also get locally declared classes that are replaceable.

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