AutoCAD本身是一个ActiveX, 用Delphi可以对他进行完全控制, 包括AutoCAD的所有
功能. 给你两个函数/过程(其中AutoCad_TLB是从ImportActiveX得来的):
type
AcadPoint = record
X: double;
Y: double;
Z: double;
end;
function AcadLine(p1,p2: ACADPoint): OleVariant;
procedure InitAcad: boolean;
var
Acad, Doc, MSpace: OleVariant;
implementation
uses ActiveX,ComObj,AutoCad_Tlb;
procedure InitAcad;
begin
result:=true;
try
acad := GetActiveOleObject('AutoCAD.Application');//get acad instance
except
on EOleSysError do
acad := CreateOleObject('AutoCAD.Application'); //create a new instance
end;
Acad.visible:= True; //show acad
Doc := Acad.ActiveDocument; //current drawing document
Mspace := Doc.ModelSpace; //module space
end;
function AcadLine(p1,p2: ACADPoint): OleVariant;
var Ps, Pe: OleVariant; //Delphi version SafeArray
begin
ps[0]:=p1.X; ps[1]:=p1.Y; ps[2]:=p1.Z;
pe[0]:=p2.X; pe[1]:=p2.Y; ps[2]:=p2.Z;
Result := Mspace.AddLine(VarArrayRef(ps), VarArrayRef(pe)).Update;
end;