Regan Blackett
08-03-2007, 12:04 PM
Flexsim v4 uses Global C++ to replace Global Code in Flexsim v3. However, you can still get the Global Code menu item by manually adding your code in the following node in Flexsim tree:
model/Tools/GlobalVarGen>variables/usercode
You need to toggle the node as Global C++ by right clicking on the node then choosing Build. Then you need to execute the command updatetoolsmenu() in a Script window. After finishing all the above, the Global Code can be found under Tools menu.
Flexsim v4's new Global C++ feature is actually more flexible than Flexsim v3's Global Code feature. In v4 you can toggle any blank text node in the model tree as Global C++, and the text of that node will be compiled as C++ code at the global scope. This allows you to distribute your code across multiple, logically separated nodes, instead of having to put a huge mess of code in one spot. Standard practice is to add these nodes in the model tools folder, and organize them as you like. Just add a node (right click on the Tools folder and choose Edit>Insert Into), give it text data (right click on the new node and choose Insert>Add String Data), and toggle it as Global C++ (right click and choose Build|Toggle as Global C++). Then write the global c++ code in the node's text data.
Before you jump into writing global code to just do things like create global variables (int, double, treenode, etc.), be sure and check out v4's new Global Variables gui in the Tools menu!
Another way to include Global C++ code in a model is to put it in a CPP file. Then create a Global C++ code under Tools menu. And in that Global C++ code, write something like:
#include "PathToCppfile\\CppFileName.cpp"Using this method, we can use another code editor, such as Microsoft Visual Studio to edit your C++ code. You also will not need to worry about whether or not the code is correctly imported into Flexsim after you make any changes in that C++ file.
model/Tools/GlobalVarGen>variables/usercode
You need to toggle the node as Global C++ by right clicking on the node then choosing Build. Then you need to execute the command updatetoolsmenu() in a Script window. After finishing all the above, the Global Code can be found under Tools menu.
Flexsim v4's new Global C++ feature is actually more flexible than Flexsim v3's Global Code feature. In v4 you can toggle any blank text node in the model tree as Global C++, and the text of that node will be compiled as C++ code at the global scope. This allows you to distribute your code across multiple, logically separated nodes, instead of having to put a huge mess of code in one spot. Standard practice is to add these nodes in the model tools folder, and organize them as you like. Just add a node (right click on the Tools folder and choose Edit>Insert Into), give it text data (right click on the new node and choose Insert>Add String Data), and toggle it as Global C++ (right click and choose Build|Toggle as Global C++). Then write the global c++ code in the node's text data.
Before you jump into writing global code to just do things like create global variables (int, double, treenode, etc.), be sure and check out v4's new Global Variables gui in the Tools menu!
Another way to include Global C++ code in a model is to put it in a CPP file. Then create a Global C++ code under Tools menu. And in that Global C++ code, write something like:
#include "PathToCppfile\\CppFileName.cpp"Using this method, we can use another code editor, such as Microsoft Visual Studio to edit your C++ code. You also will not need to worry about whether or not the code is correctly imported into Flexsim after you make any changes in that C++ file.