Venapp and External function - passing variable
Venapp and External function - passing variable
Hi everybody!
I have to pass the name of a selected variable and a selected time step to an external application from a Venapp interface.
So I need to pass the name of the variable, not the value.
Venapp has the command "SPECIAL>VARSELECT" that let the user select the variable to build a graph. I would like to catch that choice and use it in an external function, in order to pass the name of the variable to my custom application.
Any suggestion is welcome!
Many thanks
(I can't program well with language C/C++.)
I have to pass the name of a selected variable and a selected time step to an external application from a Venapp interface.
So I need to pass the name of the variable, not the value.
Venapp has the command "SPECIAL>VARSELECT" that let the user select the variable to build a graph. I would like to catch that choice and use it in an external function, in order to pass the name of the variable to my custom application.
Any suggestion is welcome!
Many thanks
(I can't program well with language C/C++.)
-
- Super Administrator
- Posts: 4841
- Joined: Wed Mar 05, 2003 3:10 am
Re: Venapp and External function - passing variable
You will need to program in C/C++ to do this.
In the external function library you will find a GLOB_VARS structure, this contains a function pointer to "get_info", you can use this to retrieve the active workbench variable which you have selected using VARSELECT.
In the external function library you will find a GLOB_VARS structure, this contains a function pointer to "get_info", you can use this to retrieve the active workbench variable which you have selected using VARSELECT.
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
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Re: Venapp and External function - passing variable
It might help if you describe what you're trying to accomplish.
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Re: Venapp and External function - passing variable
I have some variables binded to geographical zones (subscripts) and I want to create a thematic map with each of them.
My Venapp interface should let me choice a variable and a year, an external function should pass the name of the selected variable and the year to a python script.
The python script ask the vensim.dll the values of each subscripted variable and create the final bitmap image, that I can view in Venapp.
I miss the way to pass the name of the variable to the external function.
I'll learn more about the GLOB_VARS structure, but I have difficulties with C.
Thank you for the help.
My Venapp interface should let me choice a variable and a year, an external function should pass the name of the selected variable and the year to a python script.
The python script ask the vensim.dll the values of each subscripted variable and create the final bitmap image, that I can view in Venapp.
I miss the way to pass the name of the variable to the external function.
I'll learn more about the GLOB_VARS structure, but I have difficulties with C.
Thank you for the help.

-
- Super Administrator
- Posts: 4841
- Joined: Wed Mar 05, 2003 3:10 am
Re: Venapp and External function - passing variable
What you are trying to do will not be possible with external functions. For a start, you cannot use the Vensim DLL to get values, you will need to use the GLOB_VARS structure, and external functions are only executed when you press the go button on a game/simulation (what you describe is creating a report for display).
I'd suggest writing the whole interface outside of Vensim.
I'd suggest writing the whole interface outside of 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
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Re: Venapp and External function - passing variable
One possibility - if there aren't too many variables - would be to dump out all the data at the end of a run, and have python generate bitmaps for every map. Then you could load the bitmaps as needed from within Venapp. For that to work, you'd have to be able to launch the python script, which might be possible with the SHELL command. Not sure, as I haven't tried anything like this.
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Re: Venapp and External function - passing variable
I got it almost!!
Thanks to GLOB_VARS and get_info (option 21), as you told me, I can pass the name of the selected variable to my python script (through a shell command).
I miss just one step (I hope).
If I assign my external function to a variable ( C=MYFUNCT() ) it works, but every time step.
As I want it to work just after the simulation, I thought to use the "SPECIAL>EXTERNAL|MYFUNCT()" command, but it doesn't work, nothing happens.
I tried many combination, with:
"SPCECIAL>LOADDLL|VENEXT.DLL"
and
"SETTING>EXTTERNALFUNCTION|VENEXT.DLL"
as button command or normal command, with the function name lower-case or upper-case, with/without round brackets.
I'm sure the dll is loaded (an error message appears when it fails), but Venapp can't read the function as a button command.
Is it possible?
Thanks a lot.
Thanks to GLOB_VARS and get_info (option 21), as you told me, I can pass the name of the selected variable to my python script (through a shell command).
I miss just one step (I hope).
If I assign my external function to a variable ( C=MYFUNCT() ) it works, but every time step.
As I want it to work just after the simulation, I thought to use the "SPECIAL>EXTERNAL|MYFUNCT()" command, but it doesn't work, nothing happens.
I tried many combination, with:
"SPCECIAL>LOADDLL|VENEXT.DLL"
and
"SETTING>EXTTERNALFUNCTION|VENEXT.DLL"
as button command or normal command, with the function name lower-case or upper-case, with/without round brackets.
I'm sure the dll is loaded (an error message appears when it fails), but Venapp can't read the function as a button command.
Is it possible?
Thanks a lot.
-
- Super Administrator
- Posts: 4841
- Joined: Wed Mar 05, 2003 3:10 am
Re: Venapp and External function - passing variable
There is also a function in the external function library called simulation_shutdown. This is called once simulation is complete, can you use that?
Tony.
Tony.
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
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Re: Venapp and External function - passing variable
BUTTON,"shutdown",30,25,,,,,"SPECIAL>EXTERNAL|simulation_shutdown",
BUTTON,"shutdown",30,25,,,,,"SPECIAL>EXTERNAL|simulation_shutdown()",
BUTTON,"shutdown",30,25,,,,,"SPECIAL>EXTERNAL|simulation_shutdown(0)",
BUTTON,"shutdown",30,25,,,,,"SPECIAL>EXTERNAL|simulation_shutdown(1)",
I tried the four commands:
1. Venapp closes but with an error message (it asks me if i want to warn Microsoft)
2., 3., or 4. Nothing happens
BUTTON,"shutdown",30,25,,,,,"SPECIAL>EXTERNAL|simulation_shutdown()",
BUTTON,"shutdown",30,25,,,,,"SPECIAL>EXTERNAL|simulation_shutdown(0)",
BUTTON,"shutdown",30,25,,,,,"SPECIAL>EXTERNAL|simulation_shutdown(1)",
I tried the four commands:
1. Venapp closes but with an error message (it asks me if i want to warn Microsoft)
2., 3., or 4. Nothing happens
-
- Super Administrator
- Posts: 4841
- Joined: Wed Mar 05, 2003 3:10 am
Re: Venapp and External function - passing variable
No this will not work. Have a look at the following help entry
http://www.vensim.com/documentation/ind ... ?25435.htm
"SPECIAL>EXTERNAL" is not related to external functions in any way.
Look in the code for your external function library, it will contain a function called simulation_shutdown. To test it's operating ok, add in a call to display a messagebox (the function is something like ::MsgBox). Now when you run the simulation (in Vensim or Venapp), it will call simulation_shutdown at the end and the messagebox should display.
You could also try creating a function in your DLL (eg called "DoStuff"), make sure you export it. Now execute the following command.
SPECIAL>LOADDLL|YourExternalFunctionLib.dll
Then try
SPECIAL>EXTERNAL|DoStufff
That might work.
http://www.vensim.com/documentation/ind ... ?25435.htm
"SPECIAL>EXTERNAL" is not related to external functions in any way.
Look in the code for your external function library, it will contain a function called simulation_shutdown. To test it's operating ok, add in a call to display a messagebox (the function is something like ::MsgBox). Now when you run the simulation (in Vensim or Venapp), it will call simulation_shutdown at the end and the messagebox should display.
You could also try creating a function in your DLL (eg called "DoStuff"), make sure you export it. Now execute the following command.
SPECIAL>LOADDLL|YourExternalFunctionLib.dll
Then try
SPECIAL>EXTERNAL|DoStufff
That might work.
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
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Re: Venapp and External function - passing variable
I see the light...
As I told, I'm newbie in programming, but I found how to export my function:
At the end of VENEXT.C I wrote the function:
and in VENEXT.DEF, under EXPORTS, I added the line
In the Venapp file I added:
and tried it. All work fine!
Then I tried to insert the code of yesterday in my function (including some libraries: #include "stdlib.h", #include "stdio.h", #include <string.h>):
but when I click the button, Venapp crashes.
What's the problem?? My function can't work with GLOB_VARS ??
Thank you guys, you are very nice!!
As I told, I'm newbie in programming, but I found how to export my function:
At the end of VENEXT.C I wrote the function:
Code: Select all
int VEFCC testfunc()
{
MessageBox(GetActiveWindow(),"it works","Apix",
MB_ICONSTOP | MB_OK) ;
return(1) ;
}
Code: Select all
testfunc @2
In the Venapp file I added:
Code: Select all
COMMAND,"",,,,,,,"SPECIAL>LOADDLL|venext.dll",
BUTTON,"prova funzione esterna",15,19,,,,,"SPECIAL>EXTERNAL|testfunc",
Then I tried to insert the code of yesterday in my function (including some libraries: #include "stdlib.h", #include "stdio.h", #include <string.h>):
Code: Select all
int VEFCC testfunc()
{
char comando[150];
char variabile[100] ;
(*VENGV->get_info)(21,variabile,100) ;
sprintf(comando,"viewvariable.py %s",variabile) ;
system(comando);
MessageBox(GetActiveWindow(),"funge","Apix",
MB_ICONSTOP | MB_OK) ;
return(1) ;
}
What's the problem?? My function can't work with GLOB_VARS ??
Thank you guys, you are very nice!!
-
- Super Administrator
- Posts: 4841
- Joined: Wed Mar 05, 2003 3:10 am
Re: Venapp and External function - passing variable
You will need to step through the code using the debugger. It may well be that VENGV is not set in your DLL which would cause a crash. But there is no way of knowing unless you step through the code.
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
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Re: Venapp and External function - passing variable
I'm pretty lucky!
One day I'll understand what happened but in the meanwhile it works, this is the important thing.
Using both:
and
I can use my function testfunc that read the GLOB_VARS without having crashes of Venapp.
Thank you for your help!
One day I'll understand what happened but in the meanwhile it works, this is the important thing.
Using both:
Code: Select all
COMMAND,"",,,,,,,"SETTING>EXTERNALFUNCTION|venext.dll",
Code: Select all
BUTTON,"prova funzione esterna",15,19,,,,,"SPECIAL>LOADDLL|venext.dll&SPECIAL>EXTERNAL|testfunc",
Thank you for your help!
Re: Venapp and External function - passing variable
Hi again,
I would need your help for the final missing step in my Venapp interface.
Now,
1. I can select an existing variable with the command SPECIAL>VARSELECT,
2. I check it with WBVAR and SETWB
3. and I catch it through GLOB_VARS and get_info to pass it to a third application.
Through a SLIDEVAR command I'd like to choose a number (corrisponding to a time step, but it hasn't to do modfy model inputs) and catch it like the workbench variable.
Any suggestion about it? I tried in several ways but without success.
Many thanks!
I would need your help for the final missing step in my Venapp interface.
Now,
1. I can select an existing variable with the command SPECIAL>VARSELECT,
2. I check it with WBVAR and SETWB
3. and I catch it through GLOB_VARS and get_info to pass it to a third application.
Through a SLIDEVAR command I'd like to choose a number (corrisponding to a time step, but it hasn't to do modfy model inputs) and catch it like the workbench variable.
Any suggestion about it? I tried in several ways but without success.
Many thanks!
-
- Super Administrator
- Posts: 4841
- Joined: Wed Mar 05, 2003 3:10 am
Re: Venapp and External function - passing variable
Just create a dummy constant, set that using the slider, and then you should be able to get it via GLOB_VARS.
If you are actively running a simulation/game, you will need to make the dummy constant a gaming variable.
Is this what you are trying?
If you are actively running a simulation/game, you will need to make the dummy constant a gaming variable.
Is this what you are trying?
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
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Re: Venapp and External function - passing variable
I tried that ways, but without success.
If I set my dummy variable as a constant, I can use the SLIDEVAR command, but it takes effect only in the next simulation.
If the variable is a gaming auxiliar variable, I can't use the SLIDEVAR.
What I want to do should be independent from the model: I should be able to set and get the value after the simulation (without a new run).
Am I wrong about the use of gaming variables?
If I set my dummy variable as a constant, I can use the SLIDEVAR command, but it takes effect only in the next simulation.
If the variable is a gaming auxiliar variable, I can't use the SLIDEVAR.
What I want to do should be independent from the model: I should be able to set and get the value after the simulation (without a new run).
Am I wrong about the use of gaming variables?
-
- Super Administrator
- Posts: 4841
- Joined: Wed Mar 05, 2003 3:10 am
Re: Venapp and External function - passing variable
I'm not sure what you are doing, but it sounds like you have the order of things mixed up.
You can set constants before the simulation starts using a slidevar, and gaming vars during a game. If your changes require a 2nd simulation to take effect, maybe you have started the simulation before trying to set the var.
You can set constants before the simulation starts using a slidevar, and gaming vars during a game. If your changes require a 2nd simulation to take effect, maybe you have started the simulation before trying to set the var.
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
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Re: Venapp and External function - passing variable
Just a confirmation:
I loaded a model by a Venapp interface.
In parallel I ran a programm that uses the DLL.
Can the second programm, trhough the DLL, ask for info (vensim_get_info) on the model loaded by the Venapp interface? (For example, I'd like to get the names of the currently loaded runs, infowanted=10)
I don't think so, because Vensim is able to have multiple process running, isn't it?
Thanks.
I loaded a model by a Venapp interface.
In parallel I ran a programm that uses the DLL.
Can the second programm, trhough the DLL, ask for info (vensim_get_info) on the model loaded by the Venapp interface? (For example, I'd like to get the names of the currently loaded runs, infowanted=10)
I don't think so, because Vensim is able to have multiple process running, isn't it?
Thanks.
-
- Super Administrator
- Posts: 4841
- Joined: Wed Mar 05, 2003 3:10 am
Re: Venapp and External function - passing variable
Correct. They are separate processes so no communication between them.I don't think so, because Vensim is able to have multiple process running, isn't it?
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
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559