How to: Get coordinates from a symbol


Topic:

Get coordinates from a symbol


Class hierarchy:

IPCsApplication IPCsDocument IPCsDrawing IPCsPage IPCsSymbol TPCsRect


Description:

To get the coordinates from a symbols position, you should use a symbols GetRect-method. The Method takes a PsSymbolRectType as parameter, and return a TPCsRect


Sourcecode:
[+] Delphi
uses DPSCAD_TLB;

var
  PCsApplication : IPCsApplication;
  Page : IPCsPage;
  Rect : TPCsRect;
  i : integer;
begin
  PCsApplication := coApplication.Create();

  {if you want to use the currently active page}
  Page := PCsApplication.ActiveDocument.ActivePage;

  {if you want to specificly select a page}
  Page := PCsApplication.ActiveDocument.Drawing.Pages[integer];

  {running through all symbols on a page, and show the dimensions of them}
  for i := 0 to Page.Symbols.Count - 1 do
    begin
      Rect := Page.Symbols[i].GetRect(rt_Raw);
      Memo1.lines.add( 'Fullname=' + Page.Symbols[i].FullName +
        ' Left=' + Rect.Left +
        ' Top=' + Rect.Top +
        ' Right=' + Rect.Right +
        ' Bottom=' + Rect.Bottom)
    end
end;

[+] Visual Basic
Dim PCsApplication As Dpscad.IPCsApplication
Dim Page As Dpscad.PCsPage
Dim Rect As Dpscad.TPCsRect
Dim PCs As IPCsApplication

Set PCs = CreateObject("PCsELautomation.Application")

'if you want to use the currently active page
Page = PCsApplication.ActiveDocument.ActivePage

'if you want to specificly select a page
Page = PCsApplication.ActiveDocument.Drawing.Pages([integer])

'running through all symbols on a page, and show the dimensions of them
For i As Integer = 0 To Page.Symbols.Count - 1
  Rect = Page.Symbols(i).GetRect(Dpscad.PsSymbolRectType.rt_Raw)
  listBox1.Items.Add((((("Fullname=" & Page.Symbols(i).FullName & " Left=") + Rect.Left & " Top=") + Rect.Top & " Right=") + Rect.Right & " Bottom=") + Rect.Bottom)
Next

[+] C#
Dpscad.IPCsApplication PCsApplication;
Dpscad.PCsPage Page;
Dpscad.TPCsRect Rect;

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

/*if you want to use the currently active page*/
Page = PCsApplication.ActiveDocument.ActivePage;

/*if you want to specificly select a page*/
Page = PCsApplication.ActiveDocument.Drawing.Pages[integer];

/*running through all symbols on a page, and show the dimensions of them*/
for (int i = 0; i < Page.Symbols.Count; i++)
{
  Rect = Page.Symbols[i].GetRect(Dpscad.PsSymbolRectType.rt_Raw);
  listBox1.Items.Add("Fullname=" + Page.Symbols[i].FullName +
    " Left=" + Rect.Left +
    " Top=" + Rect.Top +
    " Right=" + Rect.Right +
    " Bottom=" + Rect.Bottom);
}