Edit equations using scripts

Use this forum to post Vensim related questions.
Post Reply
drw
Member
Posts: 43
Joined: Wed Mar 25, 2009 1:10 pm

Edit equations using scripts

Post by drw »

With command scripts is it possible to update an equation (specifically a string) without the model doing a simulation first?

For Background: We have a single model (mdl) which we use for multiple countries but each country has a different excel input file. We copy the file over into separate folders where the excel input file resides and want to update a variable with the name of the input file in that folder but if I use the SIMULATE>SETVAL it tries to run the model and falls over as the variable name is wrong. Is there an equivalent command I can use without the model running first? I know we could use the same name for the input file for every country but would prefer to avoid that if possible!

Thanks for your help in advance.
Administrator
Super Administrator
Posts: 4847
Joined: Wed Mar 05, 2003 3:10 am

Post by Administrator »

Is this what you need?


SIMULATE>SPREADALIAS|?alias=filename.xls

Sets an alias for a filename used in any of the GET XLS…or GET 123... functions. When the filename specified by ?alias is encountered the filename filename.xls will be substituted. The alias term must begin with a ?, and you can use just a ? (or a blank) for the empty alias reference. If filename is empty any alias that did exist will be removed (so that the user will be prompted for a filename when the model is run).
bob@vensim.com
Senior Member
Posts: 1107
Joined: Wed Mar 12, 2003 2:46 pm

Post by bob@vensim.com »

SIMULATE>SETVAL should work with string variables. This should be

SIMULATE>SETVAL|stringvar:IS:String with no quotes
drw
Member
Posts: 43
Joined: Wed Mar 25, 2009 1:10 pm

Post by drw »

Thanks so much for the suggestion. After a bit of fiddling around I was able to get a workable solution. Did find I had to replicate the file first in the existing folder and do the copy to the appropriate directory in a separate batch file later. Example below in case people interested.

So I used:

FILE>COPY|C:\path\Example1.mdl|Example2.mdl
SPECIAL>LOADMODEL|C:\path\Example2.mdl
SIMULATE>SPREADALIAS|?Input=Input2.xlsb

FILE>COPY|C:\path\Example1.mdl|Example3.mdl
SPECIAL>LOADMODEL|C:\path\Example3.mdl
SIMULATE>SPREADALIAS|?Input=Input3.xlsb

and so on...
yusuke
Member
Posts: 48
Joined: Sun Apr 27, 2008 11:41 pm

Re: Edit equations using scripts

Post by yusuke »

I am using Mac DSS version 6.00

I want to use "SPREADALIAS" command using sample model "GET XLS DATA.mdl"

1)Make a "work" directory under the "GET XLS DATA.mdl"
2)Copy "simpleInputs.xlsx" to "work" directory and change the name to simple.xlsx and change value.

make under cmd script
++
FIlE>copy|/path/GET XLS DATA.mdl|/path/work/new.mdl
SPECIAL>LOADMODEL|/path/work/new.mdl
SIMULATE>SPREADALIAS|?simpleInput.xlsx=simple.xlsx
++
To Run command,
created new.mdl and it was loaded.
but not simulating.
And there are no error message.

Please tell me how to correct

Yusuke Tarumoto
tomfid
Administrator
Posts: 4000
Joined: Wed May 24, 2006 4:54 am

Re: Edit equations using scripts

Post by tomfid »

That sample model doesn't use aliases, so you'll need to modify the equations first. For each GET XLS call that references 'simpleInputs.xlsx' you need to replace the reference with an alias like '?input' and then define the alias to point to your spreadsheet by running the model or using Model>Settings>XLS Files.

Then your method should work.
Administrator
Super Administrator
Posts: 4847
Joined: Wed Mar 05, 2003 3:10 am

Re: Edit equations using scripts

Post by Administrator »

SPREADALIAS only works when you have set up a spreadsheet alias. Eg, in an equation, you might have something like

Code: Select all

some constant = GET XLS CONSTANTS('book1.xlsx','Sheet1','A1')
this gets changed to

Code: Select all

some constant = GET XLS CONSTANTS('?XLSFILE','Sheet1','A1')
Now you can call

Code: Select all

SIMULATE>SPREADALIAS|?XLSFILE=simple.xlsx
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
yusuke
Member
Posts: 48
Joined: Sun Apr 27, 2008 11:41 pm

Re: Edit equations using scripts

Post by yusuke »

Thank you a lot.
I understand "SPREADALIAS" effect to
Model > Settings > XLS FIles

Yusuke
Post Reply