unit Unit1;
(*
This example demonstrates the use of early binding (which
requires R14.01). It creates a 3DSOLID with four holes in it.
Note that this unit requires the AutoCAD Type Library to be
imported into an Object Pascal import unit, with the name
AutoCAD_TLB.pas. It also requires AcConst.pas, which is also
available at:
http://ourworld.compuserve.com/homepages/tonyt/delphi/delphi.htm
*)
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ActiveX, ComObj, AutoCAD_TLB, AcConst;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
// Get running instance of AutoCAD or start
// New instance if start parameter is true
Function GetAcadApplication(start: Boolean): IAcadApplication;
var
v : OleVariant;
begin
Result := nil;
try
v := GetActiveOleObject('AutoCAD.Application');
Result := IDispatch(v) as IAcadApplication;
except
if start then
begin
Result := CoAcadApplication.Create;
Result.Visible := True;
end;
end;
end;
Procedure TForm1.Button1Click(Sender: TObject);
var
Acad : AcadApplication;
MSpace : AcadModelSpace;
p : OleVariant;
Box : Acad3DSolid;
Cylinder : Acad3DSolid;
begin
acad := GetAcadApplication(True);
MSpace := Acad.ActiveDocument.ModelSpace;
p := VarArrayCreate([0,2], varDouble);
p[0] := 6.0; p[1] := 6.0; p[2] := 6.0;
Box := MSpace.AddBox(p, 12.0, 12.0, 1.0);
p[0] := 2.0; p[1] := 2.0;
Cylinder := MSpace.AddCylinder(p, 1.0, 2.0);
Box.Boolean(acSubtraction, Cylinder);
p[0] := 2.0; p[1] := 10.0;
Cylinder := MSpace.AddCylinder(p, 1.0, 2.0);
Box.Boolean(acSubtraction, Cylinder);
p[0] := 10.0; p[1] := 10.0;
Cylinder := MSpace.AddCylinder(p, 1.0, 2.0);
Box.Boolean(acSubtraction, Cylinder);
p[0] := 10.0; p[1] := 2.0;
Cylinder := MSpace.AddCylinder(p, 1.0, 2.0);
Box.Boolean(acSubtraction, Cylinder);
Box.Update;
end;
end.