How to: Modify a symbol


Topic:

Modify a symbol


Class hierarchy:

IPCsApplication IPCsDocument IPCsDrawing IPCsPage IPCsSymbol


Description:

Create a variable of IPCsSymbol to store access to a symbol. A Symbol can be modified through this variable


Sourcecode:
[+] Delphi
uses DPSCAD_TLB;

var
  ADocument : IPCsDocument;
  APage : IPCsPage;
  ASymbols : IPCsSymbols;
  ASymbol : IPCsSymbol;
  PosX, PosY, PosZ : integer;
begin
  {check if we're connected to Automation}
  if CheckConnection() then    // (See function here)
    begin
      {active project}
      ADocument := PCsApplication.ActiveDocument;
      {active page}
      APage := ADocument.ActivePage;
      {all symbols}
      ASymbols := APage.Symbols;

      {get a random symbol of the symbols in the active page}
      ASymbol := ASymbols.Item[Random(ASymbols.Count)];
      {get position of that Symbol}
      ASymbol.GetPosition(PosX,PosY,PosZ);
      {modify the position of that Symbol}
      PosX := PosX + 40000;
      PosY := PosY + 30000;
      {update the Symbol with the new positions and new text}
      ASymbol.SetPosition(PosX,PosY,PosZ);
      ASymbol.FullName := 'New Symbolname';

      {update drawing in Automation through IPCsApplication}
      PCsApplication.Redraw;
    end;
end;

[+] Visual Basic
Dim ADocument As Dpscad.PCsDocument
Dim APage As Dpscad.PCsPage
Dim ASymbols As Dpscad.PCsSymbols
Dim ASymbol As Dpscad.PCsSymbol
Dim PosX, PosY, PosZ As Integer

'check if we're connected to Automation
If CheckConnection() Then   // (See function here)
  'active project
  ADocument = PCsApplication.ActiveDocument
  'active page
  APage = ADocument.ActivePage
  'all symbols
  ASymbols = APage.Symbols
  
  'get a random symbol of the symbols in the active page
  ASymbol = ASymbols(Int((ASymbols.Count + 1) * Rnd())
  'get positions of that symbol
  ASymbol.GetPosition(PosX, PosY, PosZ)
  'modify the positions of that symbol
  PosX += 40000
  PosY += 30000
  'update the symbol with the new positions
  ASymbol.SetPosition(PosX, PosY, PosZ)
  
  'update drawing in Automation through IPCsApplication
  PCsApplication.Redraw()
End If

[+] C#
Dpscad.PCsDocument ADocument;
Dpscad.PCsPage APage;
Dpscad.PCsSymbols ASymbols;
Dpscad.PCsSymbol ASymbol;
Random rnd = new Random();
int PosX, PosY, PosZ;

/*check if we're connected to Automation*/
if (CheckConnection())   // (See function here)
{
  /*active project*/
  ADocument = PCsApplication.ActiveDocument;
  /*active page*/
  APage = ADocument.ActivePage;
  /*all symbols*/
  ASymbols = APage.Symbols;

  /*get a random symbol of the symbols in the active page*/
  ASymbol = ASymbols[rnd.Next(ASymbols.Count)];
  /*get positions of that symbol*/
  ASymbol.GetPosition(out PosX, out PosY, out PosZ);
  /*modify the positions of that symbol*/
  PosX += 40000;
  PosY += 30000;
  /*update the symbol with the new positions*/
  ASymbol.SetPosition(PosX, PosY, PosZ);

  /*update drawing in Automation through IPCsApplication*/
  PCsApplication.Redraw();
}