How to: Select a project


Topic:

Select a project


Class hierarchy:

IPCsApplication IPCsDocument


Description:

To access a project in Automation, you need to create an instance of IPCsApplication first, and through that object, call (.ActiveDocument) for the currently active project, or specify precisely what number of projects you want (.Documents.Item[i])


Sourcecode:
[+] Delphi
uses DPSCAD_TLB;

var
  PCSComOb : IPCsApplication;
  ActiveDoc : IPCsDocument;
  i : integer;
begin
  PCsApplication := coApplication.Create();

  {selecting the active project}
  ActiveDoc := PCsApplication.ActiveDocument;

  {selecting a specfic project}
  i := random(PCsApplication.Documents.Count);
  ActiveDoc := PCsApplication.Documents.Item[i];
end;

[+] Visual Basic
Dim PCsApplication As Dpscad.IPCsApplication
Dim ActiveDoc As Dpscad.PCsDocument
Dim i As Integer
Dim PCs As IPCsApplication

Set PCs = CreateObject("PCsELautomation.Application")

'selecting the active project
ActiveDoc = PCsApplication.ActiveDocument

'selecting a specfic project
i = Int((PCsApplication.Documents.Count + 1) * Rnd())
ActiveDoc = PCsApplication.Documents(i)

[+] C#
Dpscad.IPCsApplication PCsApplication;
Dpscad.PCsDocument ActiveDoc;
Random rnd = new Random();
int i;

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

/*selecting the active project*/
ActiveDoc = PCsApplication.ActiveDocument;

/*selecting a specfic project*/
i = rnd.Next(PCsApplication.Documents.Count);
ActiveDoc = PCsApplication.Documents[i];