Through environments, modules can be used to completely change the interface of FlexSim. Each module can have a set of environments where each environment is a set of additions and replacements that are not applied with the rest of the module when FlexSim opens. Instead, these changes can be applied at any time by switching into an environment. Exiting the environment will restore FlexSim to it's default environment.
Environments have a set of installdata that works like a standard module, adding and replacing nodes in the tree. You can also define events or code that fires when an environment is entered into or exited. A set of options can be defined allowing you to remove the Run and FlexSim Toolbar and setting the y location of the Main Panel. You can also define a workspace, or the set of windows, that the environment opens into.
There are three locations that environments are/can be defined:
- Default Environments - Located in MAIN:/project/exec/globals/environments these environments are defined by FlexSim by default. The Default environment is what is used when exiting an environment to return to standard FlexSim. The Minimal environment removes the Run and FlexSim Toolbar and reduces the Main Menu to just a File and Execute menu with limited options. As an example, this environment may be useful if you wish to distribute your model to management or other non-FlexSim users.
- Module Environments - Modules may define any number of environments. A default environment can be defined within the module that will cause FlexSim to start in that environment when FlexSim opens.
- Model Environments - An environment may also be defined within an individual model. This allows a specific model to switch to or by default open an environment when the model is opened. For example, a module could be used to install an environment into the model which would then be opened by default whenever the model is opened. Distributing the model to co-workers would give them the associated environment without having the distribute the original module.
Creating an Environment
Creating an Environment
Adding an environment to a module is very easy. In the module node (MAIN:/modules/SomeModule), simply add a node called environments; this node should be a sibling to the module's installdata node. Within this node, create a node with the name of your environment. The environment node must contain an installdata node just like the module does that will be used to store the additions and replaces of the environment. In the end, the structure should look something like this:
Here, the ExpressIt3D module provides a single environment with the same name. An optional events node is also shown; environment events will be discussed later.
If a model environment is defined, it must follow the same structure as the modules node. This is in prepration for future developments where models may apply their own module-like changes to FlexSim.
Once this is done, you can refresh the environments by calling:
Environments in a model will be saved when the model is saved. Module environments will be saved at the same time modules are saved by calling:
Model Environment Caveats
If you have a model environment, then you can add and remove nodes to or from that environment like usual. However, you will not be able to save an environment workspace. This is because the model saves the current workspace. So if you want to make a stripped-down interface, maybe leaving only a simple menu and toolbar, then do the following. First, add and remove nodes, and set the environment options, just like you would for a module environment. Then, add a user event for OnModelOpen that switches to the environment when the model is opened. Finally, set up the UI, leaving only the desired windows open and placed properly. Then, save the model. When you open the model, the environment will be applied, followed by the workspace.
Switching to an Environment
Once an environment has been added to a model or module and environments have been refreshed, a button will appear on the right side of the user toolbar. This will display a list of all available environments to switch to.
You can also use the following command:
applicationcommand("switchtoenvironment", "Environment Name");
Order of events
The following events happen in order when an environment is being switched:
- If there is a current environment (that is not the Default FlexSim environment) the environments optional OnPreLeave command will fire.
- All changes made by the current environment as defined in the installdata node will be undone.
- The environment will fire it's optional OnPack event.
- The interface will be updated to no longer include the environment.
- The environment will fire it's optional OnLeave event.
- The entering environment will fire it's optional OnPreEnter event.
- The entering environment will unpack the data from the installdata node and apply all the defined changes.
- The entering environment will fire it's optional OnUnpack event.
- The entering environment will open it's default workspace if it exists.
- The entering environment will fire it's optional OnEnter event.
To exit an environment use and return to FlexSim's default view use:
You can also press Ctrl + Alt + E to exit an environment if no script window or Environments button is available.
Editing an Environment
In order to add or replace nodes for an environment, you must be in the environment. Once in an environment, right-clicking on a node in the tree will give you the Current Environment menu option. This option is disabled if there is no current environment.
As with a module, select Add as addition to add a node to the environment, Add as replacement to replace a node and Remove to remove an addition or replacement.
Note: When replacing a node, make sure to select Add as replacement BEFORE editing the replaced node. This will place a copy of the current state of the node into the environments installdata.
The Save active view as environment default option will save the current state of the workspace including all docked and floating windows and will be opened when the environment is first opened. If a user enters an environment and alters the window configuration and then exits the environment, the last configuration will be saved so that the user will return to that configuration when they reopen the environment. This is also the functionality of standard FlexSim. When an environment is entered the model saves off FlexSim's workspace for use when the environment is closed. This allow the user to more seamlessly switch between multiple environments and FlexSim.
- OnPreEnter - Fires when an environment is first being switched to before any changes have been applied.
- OnUnpack - Fires when the entering environment has applied all changes from it's installdata node.
- OnEnter - Fires when all changes have been applied for the entering environment.
- OnPreLeave - Fires when the current environment is being closed before any changes have been undone.
- OnUnpack - Fires after all changes from the current environment have been undone and packed into the installdata node.
- OnLeave - Fires when all changes have been undone for the exiting environment.
Environment options allow you to change aspects of FlexSim that are not available from within the tree. Though you can make some changes to the Run and FlexSim Toolbar, completely replacing them will have dire results. This is also true of the BackPanel. Changing the workspace for your environment should be done by setting the workspace to the desired layout and then selecting Save active view as environment default. The Current Environment menu option will display when right-clicking in a tree view OR when right-clicking in the space to the right of a tab pane.
You may make changes to the items in the Run Toolbar and FlexSim Toolbar, but if you wish to remove them completely and/or you want to change the y location of the BackPanel, use the following options:
- backPanelSpatialY - Specifies the spatialy value for the VIEW:/active/MainPanel/BackPanel node and properly repositions it when the environment is set.
- toolPanelSpatialY - Specifies the spatialy value of the FlexSim Toolbar.
- toolPanelSizeY - Specifies the spatialsy value of the FlexSim Toolbar.
- toolPanelDividerSpatialY - Specifies the spatialy value of the divider line between the FlexSim Toolbar and Run Toolbar.
- runPanelSpatialY - Specifies the spatialy value of the Run Toolbar.
- runPanelSizeY - Specifies the spatialsy value of the Run Toolbar.
- runPanelDividerSpatialY - Specifies the spatialy value of the divider line between the Run Toolbar and the BackPanel.
- applicationTitle - Defines the Application Title that displays in the main window.
- enterOnApplicationStart - If this is a 1, FlexSim will open into this environment when the FlexSim starts or for Model Environments, when the model is opened