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

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

eduardo_j12
Not applicable
17 Views
1 Reply
Message 1 of 2

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

eduardo_j12
Not applicable

[ FlexSim 22.1.3 ]

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



0 Likes
Accepted solutions (1)
18 Views
1 Reply
Reply (1)
Message 2 of 2

jason_lightfootVL7B4
Autodesk
Autodesk
Accepted solution

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