我怎样连接正在运行中的AUTOCAD?(50分)

  • 主题发起人 huiyugan
  • 开始时间
H

huiyugan

Unregistered / Unconfirmed
GUEST, unregistred user!

我想用DELPHI编一个使用AUTOCAD的ACTIVEX AUTOMATION功能的
程序,有没有象VB里面的GETOBJECT类似的能在AUTOCAD运行时刻
就连接上的函数,如果没有怎样能实现?THANK YOU!
 
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;
 
Wellcome ask more questions.

More points, more answers and more examples.
 
接受答案了.
 
顶部