excelvbadymola

Excel macro file to read values from Dymola


I am using an excel macro for Dymola simulation. It worked well with Dymola 2020x or 2022x. After upgrading it to 2024x, this excel tool doesn't work. I created simple dymola model and excel macro like this.

//Dymola model

model Unnamed2
  parameter Real x=1;
  Real y;
equation 
  y=2*x;
  annotation (Icon(coordinateSystem(preserveAspectRatio=false)), Diagram(
        coordinateSystem(preserveAspectRatio=false)));
end Unnamed2;

//Excel macro

Sub ExcelMacro()
Cells(1, 1) = Application.DDERequest(Application.DDEInitiate("dymola", "xxx"), "ModelicaString:x")
End Sub

If I run excel macro after simulating Dymola model in Dymola 2022x, then cell A1 returns 1. But it returns #REF! if I use Dymola 2024x. Does anyone know the solution?


Solution

  • There seems to be some preventing this from working in Dymola 2024x; it will be corrected in a future version. A work-around is to use:

    Cells(1, 1) = Application.DDERequest(Application.DDEInitiate("dymola", "xxx"), "MatlabString:x")
    

    The syntax for matrices and vectors will be slightly different in that case, but scalars will continue to work.