How to: Modify a text


Topic:

Modify a text


Class hierarchy:

IPCsApplication IPCsDocument IPCsDrawing IPCsPage IPCsText


Description:

Create a variable of IPCsText to store access to a text. A Text can be modified through this variable


Sourcecode:
[+] Delphi
uses DPSCAD_TLB;

var
  ADocument : IPCsDocument;
  APage : IPCsPage;
  ATexts : IPCsTexts;
  AText : IPCsText;
  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 texts}
      ATexts := APage.Texts;

      {get a random text of the texts in the active page}
      AText := ATexts.Item[Random(ATexts.Count)];
      {get position of that text}
      AText.GetPosition(PosX,PosY,PosZ);
      {modify the position of that text}
      PosX := PosX + 10000;
      PosY := PosY + 10000;
      {update the text with the new positions and new text}
      AText.SetPosition(PosX,PosY,PosZ);
      AText.Value := 'Brand new text';

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

[+] Visual Basic
Dim ADocument As Dpscad.PCsDocument
Dim APage As Dpscad.PCsPage
Dim ATexts As Dpscad.PCsTexts
Dim AText As Dpscad.PCsText
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 texts
  ATexts = APage.Texts
  
  'get a random text of the texts in the active page
  AText = ATexts(Int((ATexts.Count + 1) * Rnd())
  'get position of that text
  AText.GetPosition(PosX, PosY, PosZ)
  'modify the positions of that text
  PosX += 10000
  PosY += 10000
  'update the text with the new positions and new text
  AText.SetPosition(PosX, PosY, PosZ)
  AText.Value = "Brand new text"
  
  'update drawing in Automation through IPCsApplication
  PCsApplication.Redraw()
End If

[+] C#
Dpscad.PCsDocument ADocument;
Dpscad.PCsPage APage;
Dpscad.PCsTexts ATexts;
Dpscad.PCsText AText;
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 texts*/
  ATexts = APage.Texts;

  /*get a random text of the texts in the active page*/
  AText = ATexts[rnd.Next(ATexts.Count)];
  /*get position of that text*/
  AText.GetPosition(out PosX, out PosY, out PosZ);
  /*modify the positions of that text*/
  PosX += 10000;
  PosY += 10000;
  /*update the text with the new positions and new text*/
  AText.SetPosition(PosX, PosY, PosZ);
  AText.Value = "Brand new text";

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