Although Eplan P8 handles multi-level terminals pretty well, one still has to manually sort the terminal strip in order for the multi-level handling to “click” in.

Indeed, for Eplan P8 to consider terminals as being part of a single multi-level terminal (MLT), they have to be sorted by level, and this sorting has to be done manually in most cases.

For example, take the following scenario where sensors need to be connected to multi-level terminals:

Multi-level terminals 1

In this image, terminals 1,2 & 9 must be treated as a single MLT, so do terminals 3, 4 & 10 and so on.

Unfortunately, after inserting those terminals, we get the default following ordering (Project Data/Terminal Strips/Edit…):

Multi-level terminals 2

We would normally use the arrow keys (Red rectangle) to reorder the terminals to get the levels as per this image:

Multi-level terminals 3

We can see that the levels are ordered in a 1,2,3 fashion, and this is how Eplan P8 recognizes MLTs.

Using the up/down arrows can become tedious, especially if you have dozens of terminals on a single terminal strip. Here’s where this little script will come in handy.

See this video for a demonstration.

SetSortCode.cs:

//Created by Luc Morin, November 2011
//http://www.stlm.ca
public class MultiLevelSortCode
{
	[DeclareAction("SetSortCodeAction")]
	public void SetSortCodeAction()
	{
		//Use a Command Line Interpreter to call the Action
		CommandLineInterpreter CLI = new CommandLineInterpreter();
 
		Eplan.EplApi.Base.Settings set = new Eplan.EplApi.Base.Settings();
		if(!set.ExistSetting("USER.SCRIPTS.SORTCODE"))
		{
			bool bOk = set.AddNumericSetting("USER.SCRIPTS.SORTCODE",  new int[] { 0 },
				new Range[] { new Range { FromValue = 0, ToValue = 32768}}, "Sort code setting", new int[] { 0 },
				ISettings.CreationFlag.Insert);
		}
 
		int index = set.GetNumericSetting("USER.SCRIPTS.SORTCODE", 0);
 
		ActionCallingContext ctx1 = new ActionCallingContext();
		ctx1.AddParameter("propertyID","20809"); //Sort code
		ctx1.AddParameter("propertyIndex","0");
		ctx1.AddParameter("propertyValue", index.ToString());
		CLI.Execute("XEsSetPropertyAction", ctx1);
 
		set.SetNumericSetting("USER.SCRIPTS.SORTCODE", ++index, 0);
 
		return;
 
	}
 
	[DeclareMenu]
	public void SetSortCodeMenuFunction()
	{
		Eplan.EplApi.Gui.Menu oMenu = new Eplan.EplApi.Gui.Menu();
		oMenu.AddMenuItem("Set sort code", "SetSortCodeAction");
	}
 
	[DeclareAction("ResetSortCodeAction")]
	public void ResetSortCodeAction()
	{
		//Use a Command Line Interpreter to call the Action
		CommandLineInterpreter CLI = new CommandLineInterpreter();
 
		Eplan.EplApi.Base.Settings set = new Eplan.EplApi.Base.Settings();
		if(!set.ExistSetting("USER.SCRIPTS.SORTCODE"))
		{
			bool bOk = set.AddNumericSetting("USER.SCRIPTS.SORTCODE",  new int[] { 0 },
				new Range[] { new Range { FromValue = 0, ToValue = 32768}}, "Sort code setting", new int[] { 0 },
				ISettings.CreationFlag.Insert);
		}
 
		set.SetNumericSetting("USER.SCRIPTS.SORTCODE", 0, 0);
 
		return;
 
	}
 
	[DeclareMenu]
	public void ResetSortCodeMenuFunction()
	{
		Eplan.EplApi.Gui.Menu oMenu = new Eplan.EplApi.Gui.Menu();
		oMenu.AddMenuItem("Reset sort code", "ResetSortCodeAction");
	}
 
}

This script is divided in four sections, but they work in pairs. Basically, we declare two Actions and then two Menus (one per Action).

The first Action is the SetSortCodeAction, and it is used to assign the sort code to selected terminals. In order to keep track of the sort code, we create a new USER setting under USER.SETTINGS.SORTCODE. Eplan P8 allows us to define any number of such user settings, but they must be uniquely named. So, the SetSortCodeAction assign the current sort code to selected terminals, increments it, then stores it for the next call.

The ResetSortCodeAction, as its name implies, resets the current sort code to zero when we need to operate on another terminal strip. Though this is not absolutely necessary, it is a good idea to reset the sort code to zero. As far as Eplan is concerned, it doesn’t matter if the sort code starts at zero, as long as they are in numerical order.

These two Actions have associated menu points, which allows us to call them from the Utilities menu in Eplan. One can also assign these actions to shortcut keys for a more convenient way of calling them (I have assigned them to ALT-S and CTRL-S respectively).

This script makes it easier to manage the sorting of MLTs, but it still involves a certain level of manual intervention. In my next post, I’ll detail a better way to accomplish this through the API instead of a Script. This will provide a fully automated way of sorting MLTs.

As I explained in a previous post, there are limitations to what can be achieved in Scripts, and one such limitation is the fact that we can’t iterate over selected items. In a Script, we can only act over selected items as a group, so when we assign the sort code, we assign the same sort code to all selected terminals. In API, it is possible to iterate over selected terminals such that we can assign a different sort code to each. It is then possible to select the whole terminal strip, and launch the process of assigning a unique sort code to each individual terminal. This is unfortunately not possible in Scripts, so we have to manually select each group of terminals to assign the same sort code to the group.

I hope you enjoy this scripted solution. You are free to use it and redistribute it as you wish. I’ll appreciate if you would give me credit for it though.