How to: Get a symbol from a handle


Topic:

Get a symbol from a handle


Class hierarchy:

IPCsApplication IPCsDocument IPCsDrawing


Description:

When having a handle, the given symbol to that handle can be selected. The symbol is offcause of type IPCsSymbol
The method used is GetSymbolFromHandle


Sourcecode:
[+] Delphi
uses DPSCAD_TLB;
var
  PCSComOb : IPCsApplication;

procedure TForm1.GetAllSymbolsFromEntireProject();
var
  i, t : integer;
  ADrawing : IPCsDrawing;
  ASymbols : IPCsSymbols;
begin
  PCsApplication := coApplication.Create();
  {the listbox that will contain all symbols in the project}
  ListBoxSymbols.Clear;
  ADrawing := PCsApplication.ActiveDocument.Drawing;
  {running through every page in project}
  for i := 0 to ADrawing.Pages.Count - 1 do
    {only process if page is of type pt_Schematic}
    if ADrawing.Pages[i].PageType = pt_Schematic then
      begin
        ASymbols := ADrawing.Pages.Item[i].Symbols;
        for t := 0 to ASymbols.Count - 1 do
          ListBoxSymbols.Items.AddObject(ASymbols.Item[t].FullName + ' (' + inttostr(ASymbols.Item[t].Handle) + ')',TObject(ASymbols.Item[t].Handle));
      end
end;


procedure TForm1.ListBoxSymbolsClick(Sender: TObject);
var
  TheHandle : cardinal;
  ASymbol : IPCsSymbol;
begin
  {getting the handle from the listbox}
  TheHandle := IntToStr(Integer(ListBoxSymbols.Items.Objects[ListBoxSymbols.ItemIndex]));
  {set ASymbol to the symbol that the handle points to}
  ASymbol := PCsApplication.ActiveDocument.Drawing.GetSymbolFromHandle(-1,TheHandle);
  ShowMessage('Handle : "' + inttostr(TheHandle) + '" is symbol: "' + ASym.FullName + '"');
end;


[+] Visual Basic
Dim ADrawing As Dpscad.PCsDrawing
Dim ASymbols As Dpscad.PCsSymbols
Dim PCs As IPCsApplication

Set PCs = CreateObject("PCsELautomation.Application")

ADrawing = PCsApplication.ActiveDocument.Drawing

'running through every page in project
For i As Integer = 0 To ADrawing.Pages.Count - 1
  'only process if page is of type pt_Schematic
  If ADrawing.Pages(i).PageType = Dpscad.psPageType.pt_Schematic Then
    ASymbols = ADrawing.Pages(i).Symbols
    For t As Integer = 0 To ASymbols.Count - 1
      listBox1.Items.Add((ASymbols(t).FullName & " (") + ASymbols(t).Handle & ")")
    Next
  End If
Next

[+] C#
Dpscad.PCsDrawing ADrawing;
Dpscad.PCsSymbols ASymbols;

Type PCs = Type.GetTypeFromProgID("PCsELautomation.Application");
PCsApplication = (Dpscad.IPCsApplication)Activator.CreateInstance(PCs);

ADrawing = PCsApplication.ActiveDocument.Drawing;

/*running through every page in project*/
for (int i = 0; i < ADrawing.Pages.Count; i++)
{
  /*only process if page is of type pt_Schematic*/
  if (ADrawing.Pages[i].PageType == Dpscad.psPageType.pt_Schematic)
  {
    ASymbols = ADrawing.Pages[i].Symbols;
    for (int t = 0; t < ASymbols.Count; t++)
    {
      listBox1.Items.Add(ASymbols[t].FullName + " (" + ASymbols[t].Handle + ")");
    }
  }
}