July 9, 2010

How to retrieve all properties of an object

Sometimes, when you are writing a Simio design-add in that creates objects programatically, you may not know the name of a standard library object property. Then you open Simio and look in the properties pane to get its name, put in like this:

MyObject.Properties["Report Statistics"].Value = "False";

and then run your design add-in. Unfortunately, Simio confronts you qith a weird NullException! What went wrong here? Obviously, the property does not exists. This can happen because a property has a display name and a name for internal use. The name for internal use can be obtained via the IProperty.Name attribute. To do this for all properties in an object, you can use the following code in your design add-in, and delete the code afterwards:

simioObject = intelligentObjects.CreateObject("Workstation", new FacilityLocation(0, 0, 0)) as IIntelligentObject;

string names = "";

foreach(IProperty p in simioObject.Properties) {
names += "\n" + p.Name;
}

System.Windows.Forms.MessageBox.Show(names);

Happy coding!