How to: Access components through IPCsList


Topic:

Access components 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:
[+] Pascal script
uses
  Classes, Dialogs;
var
  ListOfComponents : IPCsList;
  Symbol: IPCsSymbol;
  dummy, i : integer;
  symbolnames: TStringList;
begin
  symbolnames := TStringList.create;
  {create a IPCsList of all components in active project}
  ListOfComponents := PCsApplication.ActiveDocument.Drawing.Lists.CreateComponentList('');
  {running through every item in IPCsList}
  for i := 0 to ListOfComponents.Count - 1 do
    with ListOfComponents.Item[i] do
      begin
        GetDataSymbol(0,0,Symbol,dummy);
        if Symbol <> NIL then
          symbolnames.add(Symbol.Fullname);
      end;
  symbolnames.Delimiter := #13;
  ShowMessage(symbolnames.DelimitedText);
  symbolnames.free;
end.

[+] Delphi
uses
  Classes, Dialogs, DPSCAD_TLB;
var
  ListOfComponents : IPCsList;
  Symbol: IPCsSymbol;
  dummy, i : integer;
  symbolnames: TStringList;
begin
  symbolnames := TStringList.create;
  {check if we're connected to Automation}
  if CheckConnection() then    // (See function here)
  begin
    {create a IPCsList of all components in active project}
    ListOfComponents := PCsApplication.ActiveDocument.Drawing.Lists.CreateComponentList('');
    {running through every item in IPCsList}
    for i := 0 to ListOfComponents.Count - 1 do
      with ListOfComponents.Item[i] do
        begin
          GetDataSymbol(0,0,Symbol,dummy);
          if Symbol <> NIL then
            symbolnames.add(Symbol.Fullname);
        end;
    symbolnames.Delimiter := #13;
    ShowMessage(symbolnames.DelimitedText);
  end;
  symbolnames.free;
end.

[+] Visual Basic
Dim ListOfComponents As Dpscad.PCsList
Dim Symbol As Dpscad.PCsSymbol
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
  ListOfComponents = PCsApplication.ActiveDocument.Drawing.Lists.CreateComponentList(EmptyStr)
  'running through every item in IPCsList
  For i As Integer = 0 To ListOfComponents.Count - 1
    'td_InConn, is used for getting name of Terminal, and gives symbol to Symbol
    ListOfComponents(i).GetDataSymbol(0, 0, Symbol, IndexTerm)
  Next
End If

[+] C#
Dpscad.PCsList ListOfComponents;
Dpscad.PCsSymbol Symbol;
string EmptyStr = "";

/*check if we're connected to Automation*/
if (CheckConnection())   // (See function here)
{
  /*create a IPCsList of all terminals in correct active project*/
  ListOfComponents = PCsApplication.ActiveDocument.Drawing.Lists.CreateComponentList(EmptyStr);
  /*running through every item in IPCsList*/
  for (int i = 0; i < ListOfComponents.Count; i++)
  {
    /*td_InConn, is used for getting name of Terminal, and gives symbol to Symbol*/
    ListOfComponents[i].GetDataSymbol(0, 0, out Symbol, out IndexTerm);
  }
}