question

Eduardo J12 avatar image
0 Likes"
Eduardo J12 asked Jason Lightfoot edited

Is there a way to get the value of GlobalVariable from Code using getvarnum()?

I´ve tried to get and set the value of a GlobalVariable from code, but all that I tried seems useless.

setvarnum(Model.find("MODEL:/Tools/GlobalVariables/testDLL"), "Data", 8);
double c = getvarnum(Model.find("MODEL:/Tools/GlobalVariables/testDLL"), "Data");
print(c);

and also I tried

setvarnum(Model.find("MODEL:/Tools/GlobalVariables"), "testDLL", 8);
double c = getvarnum(Model.find("MODEL:/Tools/GlobalVariables"), "testDLL");
print(c);

I know that a variable could be setted in a easy way just assignt the new value like this

testDLL=20

But that does not work for me and the type of project that I am working on. I need to get and set the variables from external dll (c++ dll - dllMaker)

NOTE.- The above code for set and get works for objects, but no with GlobalVariables



FlexSim 22.1.3
dll makerdll c++globalvariablesetvarnumgetvarnum
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Jason Lightfoot avatar image
1 Like"
Jason Lightfoot answered Jason Lightfoot edited

Accessing the data node directly sets the reset value. You can set and get that using the .value attribute as a string:

treenode gvdatanode=Model.find("Tools/GlobalVariables/myGlobalVariable/Data");
gvdatanode.value=mynewvalue;

If you want to set or get the current value try using executestring:

executestring("myGlobalVariable=4");    //set it 
return executestring("myGlobalVariable");   // get it



5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.