Unable to open *.mdl with SPECIAL>LOADMODEL

Use this forum to post Vensim related questions.
Post Reply
devM5
Junior Member
Posts: 18
Joined: Fri Jul 03, 2020 10:41 am
Vensim version: DSS

Unable to open *.mdl with SPECIAL>LOADMODEL

Post by devM5 »

Hello everyone,

I am using Microsoft Excel 2016 with VBA macros to import data from Vensim runs (*.vdf) with the 32bit Vensim DLL.

The variables that need to be read with the vensim_get_data() method are stored in a savelist (*.lst). Additionally to the base variable names, I need to retrieve the subscripts using vensim_get_varattrib().

When trying to open a model using

Code: Select all

vensim_command ("SPECIAL>LOADMODEL|C:\vensim\myModel.mdl")
I get the following error message:
error.png
error.png (5.74 KiB) Viewed 3877 times
Everything works fine when I publish the model as *.vpm file from Vensim directly, but that's not what I want. From the Vensim Help manual, I read:
"You can load both text format model (.mdl files) and binary format models (.vmf) files as well as packaged models. For anything except Vensim DSS the model needs to be contains in a package (.vpm or .vpa) file."

I have a feeling that Windows won't recognize Vensim as DSS version, although Vensim DSS for Windows Version 6.4 (x32) is installed on my computer.

Does anyone have an idea why this error pops up?

And as an alternative solution, is there another way to publish a *.vpm file from a *.mdl file with VBA in Excel?
I know there is the FILE>PUBLISH command that needs to load a model using SPECIAL>LOADMODEL in advance. Which is my primary problem :roll:

Thanks for your help!
tomfid
Administrator
Posts: 3808
Joined: Wed May 24, 2006 4:54 am

Re: Unable to open *.mdl with SPECIAL>LOADMODEL

Post by tomfid »

What page of the Help did you find this on? The .dll can't open .mdl files, by design.
devM5
Junior Member
Posts: 18
Joined: Fri Jul 03, 2020 10:41 am
Vensim version: DSS

Re: Unable to open *.mdl with SPECIAL>LOADMODEL

Post by devM5 »

I found it in the Vensim.chm help file in section DSS Reference Supplement > 5 Command Descriptions > SPECIAL > LOADMODEL|mdlname.

Is it possible to read a dataset for a variable including all subscripts in Excel-VBA using vensim_get_data()? When I export a dataset with Model > Export dataset... in Vensim, I choose a .vdf file and a .lst savelist and save the dataset to a .xls file, which will export the data for all variables in the savelist and additionally the subscripts. When I try to do the same in Excel-VBA, I don't get the subscripted variables.
Administrator
Super Administrator
Posts: 4589
Joined: Wed Mar 05, 2003 3:10 am

Re: Unable to open *.mdl with SPECIAL>LOADMODEL

Post by Administrator »

devM5 wrote: Thu Oct 08, 2020 8:47 am I found it in the Vensim.chm help file in section DSS Reference Supplement > 5 Command Descriptions > SPECIAL > LOADMODEL|mdlname.
I'm guessing you are looking at descriptions of the commands. The DLL will not load a MDL file.
devM5 wrote: Thu Oct 08, 2020 8:47 am Is it possible to read a dataset for a variable including all subscripts in Excel-VBA using vensim_get_data()? When I export a dataset with Model > Export dataset... in Vensim, I choose a .vdf file and a .lst savelist and save the dataset to a .xls file, which will export the data for all variables in the savelist and additionally the subscripts. When I try to do the same in Excel-VBA, I don't get the subscripted variables.
Can you share the commands you are using? And a screenshot of the export dialog in Vensim?
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
devM5
Junior Member
Posts: 18
Joined: Fri Jul 03, 2020 10:41 am
Vensim version: DSS

Re: Unable to open *.mdl with SPECIAL>LOADMODEL

Post by devM5 »

Administrator wrote: Thu Oct 08, 2020 9:02 am I'm guessing you are looking at descriptions of the commands. The DLL will not load a MDL file.
I see, thanks for your help. I guess I misread the help file since I'm a bloody beginner to Vensim.
Administrator wrote: Thu Oct 08, 2020 9:02 am Can you share the commands you are using? And a screenshot of the export dialog in Vensim?
Of course:
From the .lst savelist, I am reading the variable names (only variables, without subscripts) line by line in a loop until I reach the end of the savelist. Then, like proposed in the dll-examples for Excel, I call the dll with

Code: Select all

tpoints = vensim_get_data(vdfFile, varname, "time", rval(1), tval(1), 100)
and write all columns to my excel sheet

Code: Select all

For x = 1 To tpoints
	Worksheets("Sheet1").Cells(1, x + 1).Value = tval(x)
        Worksheets("Sheet1").Cells(line, x + 1).Value = rval(x)
Next
Here is the export dialog:
export.png
export.png (11.71 KiB) Viewed 3857 times
The previous way was it to export a dataset to Excel, then copy it from there and paste it into another sheet. I want to automate this process using the Vensim DLL in Excel with VBA.
Administrator
Super Administrator
Posts: 4589
Joined: Wed Mar 05, 2003 3:10 am

Re: Unable to open *.mdl with SPECIAL>LOADMODEL

Post by Administrator »

ok, I think I see what you are trying to do now.

When you call vensim_get_data, you need to provide the full parameter name (including subscripts). But you can use vensim_get_varattrib to get the subscript elements and append those onto the variable name before calling vensim_get_data.
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
devM5
Junior Member
Posts: 18
Joined: Fri Jul 03, 2020 10:41 am
Vensim version: DSS

Re: Unable to open *.mdl with SPECIAL>LOADMODEL

Post by devM5 »

I tried that already and could successfully append the subscripts to the variable names using vensim_get_varattrib after loading a .vpm file.

However, that method returns -1 (error or no variable found) when I don't load the model using vensim_command(SPECIAL>LOADMODEL|...) earlier in my VBA-script. Which I can't unless it's a .vpm file.
devM5 wrote: Wed Oct 07, 2020 5:02 pm And as an alternative solution, is there another way to publish a *.vpm file from a *.mdl file with VBA in Excel?
I know there is the FILE>PUBLISH command that needs to load a model using SPECIAL>LOADMODEL in advance.
^ just a thought: it is possible to run Vensim with a shell/cli-script, have it open a .mdl and publish it as .vpm with a list of config parameters?
Administrator
Super Administrator
Posts: 4589
Joined: Wed Mar 05, 2003 3:10 am

Re: Unable to open *.mdl with SPECIAL>LOADMODEL

Post by Administrator »

However, that method returns -1 (error or no variable found) when I don't load the model using vensim_command(SPECIAL>LOADMODEL|...) earlier in my VBA-script. Which I can't unless it's a .vpm file.
This is correct. The vensim_get_varattrib function works on the currently loaded model.
just a thought: it is possible to run Vensim with a shell/cli-script, have it open a .mdl and publish it as .vpm with a list of config parameters?
Yes. Reference manual->DSS Supplement->Command scripts. FILE>PUBLISH is the command you would need to convert the model.

http://www.vensim.com/documentation/25033.htm
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
devM5
Junior Member
Posts: 18
Joined: Fri Jul 03, 2020 10:41 am
Vensim version: DSS

Re: Unable to open *.mdl with SPECIAL>LOADMODEL

Post by devM5 »

Thanks for your help!

I was able to create a .vpm with FILE>PUBLISH in a command script, call it from Excel-VBA and then append the subscripts to my variables like I wanted. It solves the problem, but still it is not very comfortable. I would prefer to be able to load a .mdl with the DLL.
Administrator
Super Administrator
Posts: 4589
Joined: Wed Mar 05, 2003 3:10 am

Re: Unable to open *.mdl with SPECIAL>LOADMODEL

Post by Administrator »

devM5 wrote: Fri Oct 09, 2020 8:12 amI would prefer to be able to load a .mdl with the DLL.
This is a security feature. Loading a MDL would mean someone could use PLE to generate a model (or even just a text editor), and then all the advanced features of DSS (optimization, sensitivity etc) via the DLL.
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
devM5
Junior Member
Posts: 18
Joined: Fri Jul 03, 2020 10:41 am
Vensim version: DSS

Re: Unable to open *.mdl with SPECIAL>LOADMODEL

Post by devM5 »

Administrator wrote: Fri Oct 09, 2020 8:22 am
devM5 wrote: Fri Oct 09, 2020 8:12 amI would prefer to be able to load a .mdl with the DLL.
This is a security feature. Loading a MDL would mean someone could use PLE to generate a model (or even just a text editor), and then all the advanced features of DSS (optimization, sensitivity etc) via the DLL.
I see, that makes sense. Thanks for your help!
Post Reply