How to: Access terminals through IPCsList


Topic:

Access terminals through IPCsList


Class hierarchy:

IPCsList


Description:

Create a variable of IPCsList and get all symbols from a given page, into that list.
Hereafter each symbol can be accessed through that list. The IPCsList is particually usefull, when examine what a given symbol is connected to


Sourcecode:
[+] Delphi
uses DPSCAD_TLB;

Type
  TTermDataType = (td_ExtComp, td_ExtWireNo, td_ExtCable, td_ExtSignal, td_OutConn, td_InConn, td_InSignal, td_InCable, td_InWireNo, td_InComp, td_JumperLink);
var
  PCsApplication : IPCsApplication;
  ListOfTerminals : IPCsList;
  TerminalName, ConnectedToInput, ConnectedToOutput, CablesToInput, CablesToOutput, WireToInput, WireToOutput : IPCsSymbol;
  IndexTerm, i, OutInt : integer
  EmptyString : string;
begin
  {check if we're connected to Automation}
  if CheckConnection() then    // (See function here)
    begin
      {create a IPCsList of all terminals in correct active project}
      ListOfTerminals := PCsApplication.ActiveDocument.Drawing.Lists.CreateTerminalList(EmptyString);
      {running through every item in IPCsList}
      for i := 0 to ListOfTerminals.Count - 1 do
        with ListOfTerminals.Item[i] do
          begin
            {fills different Symbol-variables, with information, that shows a symbols connection to other symbols}

            {td_InConn, is used for getting name of Terminal, and gives symbol to TerminalName}
            GetDataSymbol(integer(td_InConn),0,TerminalName,IndexTerm);
            {td_InComp, which termnial is it connected to (input), and gives symbol to ConnectedToInput}
            GetDataSymbol(integer(td_InComp),0,ConnectedToInput,IndexTermInput);
            {td_ExtComp, which termnial is it connected to (output), and gives symbol to ConnectedtoOutput}
            GetDataSymbol(integer(td_ExtComp),0,ConnectedToOutput,IndexTermOutput);
            {td_InCable, what is the name of the cable (input), and gives symbol to CablesToInput}
            GetDataSymbol(integer(td_InCable),0,CablesToInput,IndexCableInput);
            {td_InCable, what is the name of the cable (output), and gives symbol to CablesToOutput}
            GetDataSymbol(integer(td_ExtCable),0,CablesToOutput,IndexCableOutput);
            {td_InWireNo, what is the name of the WireNo (input)}
            GetDataSymbol(integer(td_InWireNo),0,WireToInput,IndexWireInput);
            {td_ExtWireNo, what is the name of the WireNo (ouput)}
            GetDataSymbol(integer(td_ExtWireNo),0,WireToOutput,IndexWireOutput);
            {td_JumperLink, shows if there a bridge on this terminal}
            {if OutInt is not 0 then there is, and it's connected to all other}
            {terminals that returns the same number as OutInt is}
            GetDataInteger(integer(td_JumperLink),0,OutInt);
          end;
    end;
end;

[+] Visual Basic
Dim ListOfTerminals As Dpscad.PCsList
Dim TerminalName, ConnectedToInput, ConnectedToOutput, CablesToInput, CablesToOutput, WireToInput, WireToOutput As Dpscad.PCsSymbol
Const td_ExtComp As Integer = 0, td_ExtWireNo As Integer = 1, td_ExtCable As Integer = 2, td_ExtSignal As Integer = 3, td_OutConn As Integer = 4, td_InConn As Integer = 5, td_InSignal As Integer = 6
Const td_InCable As Integer = 7, td_InWireNo As Integer = 8, td_InComp As Integer = 9, td_JumperLink As Integer = 10
Dim IndexTerm, OutInt, IndexTermInput, IndexTermOutput, IndexCableInput, IndexCableOutput, IndexWireInput, IndexWireOutput As Integer
Dim EmptyStr As String = ""

'check if we're connected to Automation
If CheckConnection() Then   // (See function here)
  'create a IPCsList of all terminals in correct active project
  ListOfTerminals = PCsApplication.ActiveDocument.Drawing.Lists.CreateTerminalList(EmptyStr)
  'running through every item in IPCsList
  For i As Integer = 0 To ListOfTerminals.Count - 1
    'fills different Symbol-variables, with information, that shows a symbols connection to other symbols

    'td_InConn, is used for getting name of Terminal, and gives symbol to TerminalName
    ListOfTerminals(i).GetDataSymbol(td_InConn, 0, TerminalName, IndexTerm)
    'td_InComp, which termnial is it connected to (input), and gives symbol to ConnectedToInput
    ListOfTerminals(i).GetDataSymbol(td_InComp, 0, ConnectedToInput, IndexTermInput)
    'td_ExtComp, which termnial is it connected to (output), and gives symbol to ConnectedtoOutput
    ListOfTerminals(i).GetDataSymbol(td_ExtComp, 0, ConnectedToOutput, IndexTermOutput)
    'td_InCable, what is the name of the cable (input), and gives symbol to CablesToInput
    ListOfTerminals(i).GetDataSymbol(td_InCable, 0, CablesToInput, IndexCableInput)
    'td_ExtCable, what is the name of the cable (output), and gives symbol to CablesToOutput
    ListOfTerminals(i).GetDataSymbol(td_ExtCable, 0, CablesToOutput, IndexCableOutput)
    'td_InWireNo, what is the name of the WireNo (input)
    ListOfTerminals(i).GetDataSymbol(td_InWireNo, 0, WireToInput, IndexWireInput)
    'td_ExtWireNo, what is the name of the WireNo (ouput)
    ListOfTerminals(i).GetDataSymbol(td_ExtWireNo, 0, WireToOutput, IndexWireOutput)
    'td_JumperLink, shows if there a bridge on this terminal
    'if OutInt is not 0 then there is, and it's connected to all other
    'terminals that returns the same number as OutInt is
    ListOfTerminals(i).GetDataInteger(td_JumperLink, 0, OutInt)
  Next
End If

[+] C#
Dpscad.PCsList ListOfTerminals;
Dpscad.PCsSymbol TerminalName, ConnectedToInput, ConnectedToOutput, CablesToInput, CablesToOutput, WireToInput, WireToOutput;
const int td_ExtComp = 0, td_ExtWireNo = 1, td_ExtCable = 2, td_ExtSignal = 3, td_OutConn = 4, td_InConn = 5, td_InSignal = 6;
const int td_InCable = 7, td_InWireNo = 8, td_InComp = 9, td_JumperLink = 10;
int IndexTerm, OutInt, IndexTermInput, IndexTermOutput, IndexCableInput, IndexCableOutput, IndexWireInput, IndexWireOutput;
string EmptyStr = "";

/*check if we're connected to Automation*/
if (CheckConnection())   // (See function here)
{
  /*create a IPCsList of all terminals in correct active project*/
  ListOfTerminals = PCsApplication.ActiveDocument.Drawing.Lists.CreateTerminalList(EmptyStr);
  /*running through every item in IPCsList*/
  for (int i = 0; i < ListOfTerminals.Count; i++)
  {
    /*fills different Symbol-variables, with information, that shows a symbols connection to other symbols*/

    /*td_InConn, is used for getting name of Terminal, and gives symbol to TerminalName*/
    ListOfTerminals[i].GetDataSymbol(td_InConn, 0, out TerminalName, out IndexTerm);
    /*td_InComp, which termnial is it connected to (input), and gives symbol to ConnectedToInput*/
    ListOfTerminals[i].GetDataSymbol(td_InComp, 0, out ConnectedToInput, out IndexTermInput);
    /*td_ExtComp, which termnial is it connected to (output), and gives symbol to ConnectedtoOutput*/
    ListOfTerminals[i].GetDataSymbol(td_ExtComp, 0, out ConnectedToOutput, out IndexTermOutput);
    /*td_InCable, what is the name of the cable (input), and gives symbol to CablesToInput*/
    ListOfTerminals[i].GetDataSymbol(td_InCable, 0, out CablesToInput, out IndexCableInput);
    /*td_ExtCable, what is the name of the cable (output), and gives symbol to CablesToOutput*/
    ListOfTerminals[i].GetDataSymbol(td_ExtCable, 0, out CablesToOutput, out IndexCableOutput);
    /*td_InWireNo, what is the name of the WireNo (input)*/
    ListOfTerminals[i].GetDataSymbol(td_InWireNo, 0, out WireToInput, out IndexWireInput);
    /*td_ExtWireNo, what is the name of the WireNo (ouput)*/
    ListOfTerminals[i].GetDataSymbol(td_ExtWireNo, 0, out WireToOutput, out IndexWireOutput);
    /*td_JumperLink, shows if there a bridge on this terminal
     if OutInt is not 0 then there is, and it's connected to all other
    terminals that returns the same number as OutInt is*/
    ListOfTerminals[i].GetDataInteger(td_JumperLink, 0, out OutInt);
  }
}