Simio
  • Design Add-In Interactive Window

  • Do you have objects, models, libraries, path decorators, textures, symbols, custom API code, documentation, or anything else others might find useful? Please attach it here with a brief description.
Do you have objects, models, libraries, path decorators, textures, symbols, custom API code, documentation, or anything else others might find useful? Please attach it here with a brief description.
 #2680  by msilverwood2
 Tue Oct 23, 2012 8:01 am
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.

Disclaimer: I'm an engineer that is mostly self-taught when it comes to programming so it may not work (all I know is that it works on my pc :) ). Also I know that it isn't the prettiest piece of software either.

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: http://en.wikipedia.org/wiki/Read%E2%80 ... print_loop

The code uses the Microsoft Roslyn Compiler API. more info here: http://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: http://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.

How to install:
1) Copy the SimioREPL folder from the zip file into either: C:\Program Files\Simio\UserExtensions or c:\Program Files (x86)\Simio\UserExtensions
2) The folder structure should be ..\Simio\UserExtensions\SimioREPL

How to get started:
1) Create a new model in simio.
2) Select SimioREPL from the Select Add-In drop Menu (Project Home Ribbon)
3) Click "Insert Initializing Code" button. This inserts some code to get the whole thing going. You may need to change the directory of the dlls loaded if you are not using a 64-bit machine (delete the x86 part from the path).
4) Press the Execute button to evaluate the code.
5) 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.

How to use (here is an example of how to use the tool):
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.

Some example code Walkthrough:
Add some objects to the model
Code: Select all
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]


Move the source object
Code: Select all
intelligentObjects["Source1"].Location = new FacilityLocation(-4.5, 0, -2);
[Execute]


List all the nodes on the server object
Code: Select all
foreach(var node in serverObject.Nodes)
{
      WriteLine(node);
}
[Execute]


List all the objects in the model
Code: Select all
foreach(var ob in intelligentObjects)
{
 WriteLine(ob.ObjectName);
}
[Execute]

----------

Hopefully you find this useful. If you improve the tool using the Source Code given then could you please repost the source code here in this forum topic. I'm sure that there are many things that can be improved by a proper programmer. What it really needs is intellisense :D .
Attachments
User Extension
(1.96 MiB) Downloaded 637 times
VS2012 Solution (Source Code)
(55.12 KiB) Downloaded 645 times
 #2681  by agraunke
 Tue Oct 23, 2012 5:28 pm
That is super cool!

Two hiccups I had on installation:
1. You need to "unblock" the dlls
2. This requires .NET 4.5

I did not need VS2012, and I have it working on sprint 78.

Thanks for this (and the info on the Roslyn compliler API)!

-Adam
 #2682  by jdoran
 Tue Oct 23, 2012 8:14 pm
Very cool. Nice contribution.

Before I even use it though, I know I am going to want intellisense. :(

Just to be silly, I took two screenshots of the first thing I did, and probably one of the most common tasks I will be doing. Placing objects according to an expression.
Attachments
2012-10-24_11-05-16.png
2012-10-24_11-05-16.png (174.94 KiB) Viewed 8002 times
2012-10-24_11-05-25.png
2012-10-24_11-05-25.png (228.89 KiB) Viewed 8002 times