How to: Add to a LibType


Topic:

Add to a LibType


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;
  ASymbol : IPCsSymbol;
  APt : TPCsPoint3D;
  ALibType : IPCsLibType;
  ALine : IPCsLine;
  Xorg, YOrg, ZOrg, XMove, YMove : 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;
      {assigning valus to TPCsPoint3D}
      APt.X := 10000;
      APt.Y := 10000;
      APt.Z := 0;
      {creating an instance of a IPCsLibType}
      ALibType := Adocument.Drawing.LibTypes.Add('SymbolFileName');
      {create line}
      ALine := ALibType.Lines.Add();
      XOrg := 20000;
      YOrg := 20000;
      ZOrg := 0;
      XMove := 30000;
      YMove := 30000;
      {adding points, which make a square}
      ALine.AddPointXYZ(Xorg,YOrg,ZOrg);
      ALine.AddPointXYZ(Xorg+XMove,YOrg,Zorg);
      ALine.AddPointXYZ(Xorg+XMove,YOrg+YMove,Zorg);
      ALine.AddPointXYZ(Xorg,YOrg+YMove,Zorg);
      ALine.AddPointXYZ(Xorg,YOrg,ZOrg);
      {create a symbol, from LibType}
      ASymbol := Apage.Symbols.Add(ALibType);
      {setting position}
      ASymbol.Position := Apt;
      ASymbol.SymbolTexts.NameText.Value := 'My Symbol'
    end;
end;

[+] Visual Basic
Dim ADocument As Dpscad.PCsDocument
Dim APage As Dpscad.PCsPage
Dim ASymbol As Dpscad.PCsSymbol
Dim APt As Dpscad.TPCsPoint3D
Dim ALibType As Dpscad.PCsLibType
Dim ALine As Dpscad.PCsLine
Dim XOrg, YOrg, ZOrg, XMove, YMove As Integer

If CheckConnection() Then   // (See function here)
  'active project
  ADocument = PCsApplication.ActiveDocument
  'active page
  APage = ADocument.ActivePage
  'assigning valus to TPCsPoint3D
  APt.X = 10000
  APt.Y = 10000
  APt.Z = 0
  'creating an instance of a IPCsLibType
  ALibType = ADocument.Drawing.LibTypes.Add("SymbolFileName")
  'create line
  ALine = ALibType.Lines.Add()
  XOrg = 20000
  YOrg = 20000
  ZOrg = 0
  XMove = 30000
  YMove = 30000
  'adding points, which make a square
  ALine.AddPointXYZ(XOrg, YOrg, ZOrg)
  ALine.AddPointXYZ(XOrg + XMove, YOrg, ZOrg)
  ALine.AddPointXYZ(XOrg + XMove, YOrg + YMove, ZOrg)
  ALine.AddPointXYZ(XOrg, YOrg + YMove, ZOrg)
  ALine.AddPointXYZ(XOrg, YOrg, ZOrg)
  'create a symbol, from LibType
  ASymbol = APage.Symbols.Add(ALibType)
  'setting position
  ASymbol.Position = APt
  ASymbol.SymbolTexts.NameText.Value = "My Symbol"
End If

[+] C#
Dpscad.PCsDocument ADocument;
Dpscad.PCsPage APage;
Dpscad.PCsSymbol ASymbol;
Dpscad.TPCsPoint3D APt;
Dpscad.PCsLibType ALibType;
Dpscad.PCsLine ALine;
int XOrg, YOrg, ZOrg, XMove, YMove;

if (CheckConnection())   // (See function here)
{
  /*active project*/
  ADocument = PCsApplication.ActiveDocument;
  /*active page*/
  APage = ADocument.ActivePage;
  /*assigning valus to TPCsPoint3D*/
  APt.X = 10000;
  APt.Y = 10000;
  APt.Z = 0;
  /*creating an instance of a IPCsLibType*/
  ALibType = ADocument.Drawing.LibTypes.Add("SymbolFileName");
  /*create line*/
  ALine = ALibType.Lines.Add();
  XOrg = 20000;
  YOrg = 20000;
  ZOrg = 0;
  XMove = 30000;
  YMove = 30000;
  /*adding points, which make a square*/
  ALine.AddPointXYZ(XOrg, YOrg, ZOrg);
  ALine.AddPointXYZ(XOrg + XMove, YOrg, ZOrg);
  ALine.AddPointXYZ(XOrg + XMove, YOrg + YMove, ZOrg);
  ALine.AddPointXYZ(XOrg, YOrg + YMove, ZOrg);
  ALine.AddPointXYZ(XOrg, YOrg, ZOrg);
  /*create a symbol, from LibType*/
  ASymbol = APage.Symbols.Add(ALibType);
  /*setting position*/
  ASymbol.Position = APt;
  ASymbol.SymbolTexts.NameText.Value = "My Symbol";
}