How to: Select page in project


Topic:

Select page in project


Class hierarchy:

IPCsApplication IPCsDocument IPCsDrawing IPCsPages


Description:

To access a page in a project in Automation, you need to create a instace of IPCSApplication first, and through that object either select the currently active project or select a specfic project. From here, call either .ActivePage, or .Drawing.Pages[i]


Sourcecode:
[+] Delphi
uses DPSCAD_TLB;

var
  PCSComOb : IPCsApplication;
  i, t : integer;
  page : IPCsPage;
begin
  PCsApplication := coApplication.Create();

  {get active page in active project}
  i := PCsApplication.ActiveDocument.ActivePage.Index;
  page := PCsApplication.ActiveDocument.Drawing.Pages[i];

  {get specific page in active project}
  i := Random(PCsApplication.Drawing.Pages.Count)
  page := PCsApplication.ActiveDocument.Drawing.Pages[i];

  {get active page in antoher project}
  t := random(PCsApplication.Documents.Count)
  i := PCsApplication.Documents.Item[t].ActivePage.Index
  page := PCsApplication.Documents.Item[t].Drawing.Pages[i];

  {set active a specific page in project}
  page := PCsApplication.ActiveDocument.Drawing.Pages[4];
  PCsApplication.ActiveDocument.ActivePage := Page;

end;

[+] Visual Basic
Dim PCsApplication As Dpscad.IPCsApplication
Dim APage As Dpscad.PCsPage
Dim i, t As Integer
Dim PCs As IPCsApplication

Set PCs = CreateObject("PCsELautomation.Application")

'get active page in active project
i = PCsApplication.ActiveDocument.ActivePage.Index
APage = PCsApplication.ActiveDocument.Drawing.Pages(i)

'get specific page in active project
i = Int((PCsApplication.ActiveDocument.Drawing.Pages.Count + 1) * Rnd())
APage = PCsApplication.ActiveDocument.Drawing.Pages(i)

'get active page in antoher project
t = rnd.[Next](PCsApplication.Documents.Count)
i = PCsApplication.Documents(t).ActivePage.Index
APage = PCsApplication.Documents(t).Drawing.Pages(i)

'set active a specific page in project
APage = PCsApplication.ActiveDocument.Drawing.Pages(4)
PCsApplication.ActiveDocument.ActivePage = APage

[+] C#
Dpscad.IPCsApplication PCsApplication;
Dpscad.PCsPage APage;
Random rnd = new Random();
int i, t;

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

/*get active page in active project*/
i = PCsApplication.ActiveDocument.ActivePage.Index;
APage = PCsApplication.ActiveDocument.Drawing.Pages[i];

/*get specific page in active project*/
i = rnd.Next(PCsApplication.ActiveDocument.Drawing.Pages.Count);
APage = PCsApplication.ActiveDocument.Drawing.Pages[i];

/*get active page in antoher project*/
t = rnd.Next(PCsApplication.Documents.Count);
i = PCsApplication.Documents[t].ActivePage.Index;
APage = PCsApplication.Documents[t].Drawing.Pages[i];

/*set active a specific page in project*/
APage = PCsApplication.ActiveDocument.Drawing.Pages[4];
PCsApplication.ActiveDocument.ActivePage = APage;