Page 1 of 1
Edit equations using scripts
Posted: Thu Apr 23, 2009 6:25 pm
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.
Posted: Fri Apr 24, 2009 9:00 am
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).
Posted: Fri Apr 24, 2009 10:06 am
by bob@vensim.com
SIMULATE>SETVAL should work with string variables. This should be
SIMULATE>SETVAL|stringvar:IS:String with no quotes
Posted: Fri Apr 24, 2009 5:50 pm
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...
Re: Edit equations using scripts
Posted: Wed Jul 18, 2012 5:45 am
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
Re: Edit equations using scripts
Posted: Wed Jul 18, 2012 1:54 pm
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.
Re: Edit equations using scripts
Posted: Wed Jul 18, 2012 1:56 pm
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
Re: Edit equations using scripts
Posted: Wed Jul 18, 2012 10:28 pm
by yusuke
Thank you a lot.
I understand "SPREADALIAS" effect to
Model > Settings > XLS FIles
Yusuke