Module SDK Quick Start
Overview and Key Concepts
This document explains how to create a FlexSim module quickly and easily. Before starting, make sure you have the latest version of Visual Studio (Community or Professional) installed.
Preparing for Module Development
These steps are more general, and usually only need to be done once, even if you are developing multiple modules.
Making a Development Version of FlexSim
To prepare for module development, we recommend that you make a development version of FlexSim. This can be done in two easy steps:
- In your Documents folder, make a new folder called "ModuleDevelopment" or a similar helpful name
- Copy C:\Program Files\FlexSim 2021 (or the latest version of FlexSim) and paste it into your development directory
This creates a copy of FlexSim. During development, you should use this copy of FlexSim. For convenience, you may want to make a shortcut to this version:
- In your development directory, navigate to FlexSim\program
- Right click on flexsim.exe and choose Create Shortcut
- Name the shortcut something like "FlexSimDev" and move it to your desktop
If you desire, you can configure the development copy of FlexSim to use a different User Preferences file. (This makes it so the development copy can be put in development mode, and leaves the intalled copy alone.)
- In your development directory, navigate to FlexSim\program
- Open the file called productid.txt in a text editor
- Change the first line to a meaningful name, like ModuleDev
You can make as many development versions of FlexSim as you need.
Enabling Development Tools in FlexSim
FlexSim has some development tools built in, but they are not enabled by default. To enable them, do the following:
- Open your development version of FlexSim
- Add a node at VIEW:/environment/dev
- Give that node number data, and set it to 1
- Close FlexSim (which saves the new node as a user preference)
Next time you open FlexSim, the dev node will still be there, and additional options will be available in your right-click menu.
Creating a Save Defaults Button
As you add nodes to the tree as part of your module, you will want to save your progress. The most convenient way to do this is to add a button to FlexSim to save your module changes:
- Open your development version of FlexSim
- From the File menu, open the Global Preferences window
- On the Customize Toolbar tab, add a new button
- Select the new button in the list, and click Edit Item
- Change its name to "Save Defaults", and replace the example code with the following:
applicationcommand("savedefaultviewproject");
- Click OK, then click Apply and Close
- Close FlexSim to save these changes to global preferences
Creating a New Module
Now you are ready to create a new module. Choose a name for your module. It should be helpful and short, and should not contain any spaces. Good example names include "ProcessFlow" and "AStar".
In order to create a new module, you need to create a folder for the new module. Do so as follows:
- In your development directory, navigate to FlexSim\modules
- Create a new folder with the name of your module
Next, you need to add the essential module nodes to FlexSim:
- Open your development version of FlexSim
- In the tree, go to MAIN:/project/modules
- Add a node with the name of your module
- Add a subnode to that node called installdata
- Click the Save Defaults button
Adding Nodes
Once you have completed these steps, you can begin adding nodes to your module:
- Add a node to the tree
- Right-click the node
- Choose Modules > [ModuleName] > Add as Addition
Once you have added a node to your module, you can edit that node by giving it data or subnodes. When you have finished editing that node, click the Save Defaults button to save your work.
Adding a DLL Project to your Module
Some modules extend FlexSim's functionality with custom C++ code. In order to do this, follow these steps:
- Download module_template.zip
- Extract the ModuleDLL folder to FlexSim\modules\[ModuleName] in your development directory
- Copy the files from FlexSim\program\system\include to the ModuleDLL\flexsimcontent directory
- Copy flexsim.lib from FlexSim\program\system\lib to the ModuleDLL\flexsimcontent directory
- Open the ModuleDLL\module.sln file in the latest version of Visual Studio
- In the Solution Explorer pane, right-click the project and select Rename
- Rename the project from "module" to the name of your module
- In the Solution Explorer pane, right-click on the Source Files folder, point to Add, and choose Existing Item... to browse for a file.
- Navigate to the ModuleDLL\flexsimcontent folder, choose DllMain.cpp, and click Add to add this file to the project.
- Build the solution. It should build and link without any errors. A [ModuleName].dll file should be generated in your module's directory.