I've created a tool which makes my life a bit easier when trying to code Design Add-Ins for Simio and I thought that I would share it with everyone else.
What the tool does is allow you to try c# code directly within Simio and evaluate the results. If you have ever used a dynamic programming language like Matlab or Mathematica then it will be familiar to you. Its like the command window in Matlab where you can enter commands without compiling. Its called a REPL (Read-Eval-Print-Loop). more info here: https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop
The code uses the Microsoft Roslyn Compiler API. more info here: https://en.wikipedia.org/wiki/Microsoft_Roslyn If you want to play around with the source code then you will probably need to install the Roslyn CTP. Download here: https://msdn.microsoft.com/en-gb/roslyn. I created the solution using Visual Studio 2012 and I believe that the roslyn compiler only works with VS 2012 at the moment.
You can get the latest version inside the Latest Compiled Release
folder.
- Install dll into either:
C:\Program Files (x86)\Simio\UserExtensions\SimioREPL\SimioREPL.dll
orC:\Program Files\Simio\UserExtensions\SimioREPL\SimioREPL.dll
- The folder structure should be
..\Simio\UserExtensions\SimioREPL
- The drop-down code snippet tool (green drop-down) loads stored functions stored in the following file:
c:\SimioReferences\REPL_Functions.txt
.
- Create a new model in simio.
- Select SimioREPL from the Select Add-In drop Menu (Project Home Ribbon)
- You can now start playing with the interactive coding environment
The bottom textbox displays the results from each execution loop. If no return values are given then it will display just the execution count.
Enter c# code just like in a normal program, for example:
int x = 10;
You can find out the current value of a variable by entering its name without the ending semi-colon, for example:
x or x*2 + 10 -3
This will display the value in the output text box at the bottom of the window.
I've added the ability to use Write()
and WriteLine()
, just like in a console application. for example:
WriteLine(object.ObjectName);
If the code is invalid then the Exception message will be displayed in the results text box, and the input code will remain. If the code is valid then the input code is cleared.
The context object is already defined. Use context as you normally would.
Add some objects to the model
IIntelligentObjects intelligentObjects = context.ActiveModel.Facility.IntelligentObjects;
IFixedObject sourceObject = intelligentObjects.CreateObject("Source", new FacilityLocation(-5, 0, -5)) as IFixedObject;
IFixedObject serverObject = intelligentObjects.CreateObject("Server", new FacilityLocation(0, 0, 0)) as IFixedObject;
IFixedObject sinkObject = intelligentObjects.CreateObject("Sink", new FacilityLocation(5, 0, 5)) as IFixedObject;
ILinkObject path1 = intelligentObjects.CreateLink("Path",sourceObject.Nodes[0],serverObject.Nodes[0],null) as ILinkObject;
ILinkObject path2 = intelligentObjects.CreateLink("Path",serverObject.Nodes[1],sinkObject.Nodes[0],null) as ILinkObject;
[Execute]
<ctrl + enter> or
Move the source object
intelligentObjects["Source1"].Location = new FacilityLocation(-4.5, 0, -2);
[Execute]
List all the nodes on the server object
foreach(var node in serverObject.Nodes)
{
WriteLine(node);
}
[Execute]
List all the objects in the model Code:
foreach(var ob in intelligentObjects)
{
WriteLine(ob.ObjectName);
}
[Execute]
License: GNU General Public License version 3 (GPLv3)