How to: Modify a line


Topic:

Modify a line


Class hierarchy:

IPCsApplication IPCsDocument IPCsDrawing IPCsPage IPCsLine


Description:

Create a variable of IPCsLine to store access to a line. A Line can be modified through this variable


Sourcecode:
[+] Delphi
uses DPSCAD_TLB;

var
  ADocument : IPCsDocument;
  APage : IPCsPage;
  ALines : IPCsLines;
  ALine : IPCsLine;
  RandomPoint : integer;
  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 lines}
      ALines := APage.Lines;

      {get a random line of the lines in the active page}
      ALine := ALines.Item[Random(ALines.Count)];
      {get a random point of the selected line}
      RandomPoint := Random(ALine.Points.Count);
      {get positions of that point}
      ALine.Points.Item[RandomPoint].GetPosition(PosX,PosY,PosZ);
      {modify the positions of that point}
      PosX := PosX + 10000;
      PosY := PosY + 10000;
      {update the line with the new positions}
      ALine.Item[RandomPoint].SetPosition(PosX,PosY,PosZ);

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

[+] Visual Basic
Dim ADocument As Dpscad.PCsDocument
Dim APage As Dpscad.PCsPage
Dim ALines As Dpscad.PCsLines
Dim ALine As Dpscad.PCsLine
Dim PosX, PosY, PosZ, RandomPoint 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 lines
  ALines = APage.Lines
  
  'get a random line of the lines in the active page
  ALine = ALines(rnd.[Next](ALines.Count))
  'get a random point of the selected line
  RandomPoint = Int((ALines.Count + 1) * Rnd()))
  'get positions of that point
  ALine.Points(RandomPoint).GetPosition(PosX, PosY, PosZ)
  'modify the positions of that point
  PosX += 10000
  PosY += 10000
  'update the line with the new positions
  ALine.Points(RandomPoint).SetPosition(PosX, PosY, PosZ)
  
  'update drawing in Automation through IPCsApplication
  PCsApplication.Redraw()
End If

[+] C#
Dpscad.PCsDocument ADocument;
Dpscad.PCsPage APage;
Dpscad.PCsLines ALines;
Dpscad.PCsLine ALine;
Random rnd = new Random();
int PosX, PosY, PosZ, RandomPoint;

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

  /*get a random line of the lines in the active page*/
  ALine = ALines[rnd.Next(ALines.Count)];
  /*get a random point of the selected line*/
  RandomPoint = rnd.Next(ALine.Points.Count);
  /*get positions of that point*/
  ALine.Points[RandomPoint].GetPosition(out PosX, out PosY, out PosZ);
  /*modify the positions of that point*/
  PosX += 10000;
  PosY += 10000;
  /*update the line with the new positions*/
  ALine.Points[RandomPoint].SetPosition(PosX, PosY, PosZ);

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