I don't know exactly what is happening with Python at the moment, but I can answer what happens inside Dymola:

When you start a program from Start-Menu the current directory is as default set to the installation directory of the program (in this case Dymola).
Not important: When Dymola is started it first ensures that .\Documents\Dymola exists.
Not important: If the environment variable DYMOLAWORKDIRECTORY is not set it is set to .\Documents\Dymola
If the current directory is the same as the installation directory of Dymola then it sets current directory to .\Documents\Dymola - otherwise it keeps the current directory. This allows you to make a short-cut "Start Dymola Here!"
And then the settings where you might have changed 'Startup Directory' is processed.

But I don't know why the Python-interface changes current directory to .\project, and if you could change current directory in Python.
I just noticed an odd behavior in Dymola 2022, and I wonder if and how can I take care of it from the Python interface.
Odd behavior, because I expect Dymola to consistently set the working directory at .\Documents\Dymola at startup, unless told otherwise.
However, when I instantiate Dymola from its Python interface, at startup the working directory is set according to the setting Tools > Options > Settings > Save startup directory as follows:

Do not save - then when I instantiate Dymola, the current directory is set as the directory where the python environment is open. Possibly interesting here:

the directory where the python environment is open is not the directory where the function is located.

Example: in VSCode open folder > .\project, the function is in .\project\functions\dymIO\instantiateDymola.py, then the Dymola working directory at startup is set at .\project




Save this directory > .\Documents\Dymola - then the current directory is set reliably at .\Documents\Dymola


One solution/fix would be to set the working directory after Dymola is instantiated, I am aware of it.
My question is rather to get an understanding of what might be going on with this behavior, and if there is a possibility to take care of it right at startup rather than afterwards
Default startup directory behavior in Dymola 2022