Edit equations using scripts

Use this forum to post Vensim related questions.

Edit equations using scripts

Postby drw » Thu Apr 23, 2009 6:25 pm

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.
drw
Junior Member
 
Posts: 18
Joined: Wed Mar 25, 2009 1:10 pm

Postby Administrator » Fri Apr 24, 2009 9:00 am

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).
Administrator
Super Administrator
 
Posts: 1411
Joined: Wed Mar 05, 2003 3:10 am

Postby bob@vensim.com » Fri Apr 24, 2009 10:06 am

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

SIMULATE>SETVAL|stringvar:IS:String with no quotes
bob@vensim.com
Senior Member
 
Posts: 1107
Joined: Wed Mar 12, 2003 2:46 pm

Postby drw » Fri Apr 24, 2009 5:50 pm

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...
drw
Junior Member
 
Posts: 18
Joined: Wed Mar 25, 2009 1:10 pm

Re: Edit equations using scripts

Postby yusuke » Wed Jul 18, 2012 5:45 am

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
yusuke
Member
 
Posts: 38
Joined: Sun Apr 27, 2008 11:41 pm

Re: Edit equations using scripts

Postby tomfid » Wed Jul 18, 2012 1:54 pm

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.
/*
Advice to posters (it really helps us to help you)
viewtopic.php?f=2&t=4391

Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics

*/
tomfid
Administrator
 
Posts: 812
Joined: Wed May 24, 2006 4:54 am
Location: Montana, USA

Re: Edit equations using scripts

Postby Administrator » Wed Jul 18, 2012 1:56 pm

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/viewtopic.php?f=2&t=4391
Administrator
Super Administrator
 
Posts: 1411
Joined: Wed Mar 05, 2003 3:10 am

Re: Edit equations using scripts

Postby yusuke » Wed Jul 18, 2012 10:28 pm

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

Yusuke
yusuke
Member
 
Posts: 38
Joined: Sun Apr 27, 2008 11:41 pm


Return to Vensim

Who is online

Users browsing this forum: No registered users and 0 guests

cron