Ide Indy Delphi

Title: Using Delphi with Autocad
Question: I have an Industrial database application in Delphi with several equipment. Also I have a plant layout in Autocad, and several Process Flow Diagrams (PFD) also in Autocad.
How can I show the location of the equipment or the PFD to the users?
Answer:
In this example we let Autocad start up, Open a file and zoom in to a desired location.
We will to this for Acad-14, and Acad-2000
We will need a form with a button, add the units ActiveX, ComObj and OleCtnrs.
unit AcadTest2000;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ActiveX, ComObj, OleCtnrs;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
p1, p2 : OleVariant;
Acad, ActiveDoc, : OleVariant;
begin
// create variant arrays to hold coordinates of the window
p1 := VarArrayCreate([0,2], VT_R8);
p2 := VarArrayCreate([0,2], VT_R8);
// assign values to array elements
p1[0] := 14330.0; p1[1] := 400.0; p1[2] := 0; //point (14330,400,0)
p2[0] := 26400.0; p2[1] := 8500.0; p2[2] := 0; //point (26400,8500,0)
Acad := CreateOleObject('AutoCad.Application');
if not varisempty(Acad) then
Acad.visible := visible;
// open drawing
ActiveDoc := Acad.Documents.Open('E:\Home\Planview.dwg');
// zoom appliciation
Acad.ZoomExtents;
Acad.ZoomWindow(VarArrayRef(p1),VarArrayRef(p2));
end;
end.
The Approach for Acad-14 is different. The ZoomExtents and ZoomWindow methods apply to a viewport, also the sintaxe of opening a file is different
unit AcadTest14;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ActiveX, ComObj, OleCtnrs;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
p1, p2 : OleVariant;
Acad, ActiveDoc, ViewPort : OleVariant;
begin
// create variant arrays to hold coordinates of the window
p1 := VarArrayCreate([0,2], VT_R8);
p2 := VarArrayCreate([0,2], VT_R8);
// assign values to array elements
p1[0] := 14330.0; p1[1] := 400.0; p1[2] := 0; //point (14330,400,0)
p2[0] := 26400.0; p2[1] := 8500.0; p2[2] := 0; //point (26400,8500,0)
Acad := CreateOleObject('AutoCad.Application.14');
if not varisempty(Acad) then
Acad.visible := visible;
// open drawing
ActiveDoc := Acad.ActiveDocument.Open('E:\Home\Planview.dwg');

//Activate viewport
ViewPort := ActiveDoc.ActiveViewPort;
// zoom appliciation
ViewPort.ZoomExtents;
ViewPort.ZoomWindow(VarArrayRef(p1),VarArrayRef(p2));
end;
end.