|
发表于 2002-9-14 10:03:00
|
显示全部楼层
基本上我是看ACAD中ACTIVEX AUTOMAIION的说明后再将其VBA的语法翻成DELPHI编程,下面是一个简单打开ACAD后画圆的例子(delphi4.0,acad14.01)
运行后应重显示ACAD。
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,comobj;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
acad,ac,act,mdp,point,inpoint,sset:OleVariant;
cir,rr,dd,ttlevariant;
r:real;
count:integer;
textString:string;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
acad:= GetActiveOleObject('AutoCAD.Application');//连接已打开的ACAD
// acad:= CreateOleObject('AutoCAD.Application');//创建新的ACAD
acad.Visible := True; //ACAD可显示
ac:=acad.activedocument; //AC为ACAD对象的子对象
mdp :=ac.modelspace; //MDP为AC的模型空间子对象
Point:=VarArrayCreate([0, 2], vardouble);//定义三维可变数组
Point[0]:=15.4 ;
Point[1]:=5.4 ;
Point[2]:=0.0 ;
r:=12; //定义半径值
textString:='This is a test String'; //定义字符串
mdp.AddText(textString,vararrayref(point),r);// 写文字
mdp.Addcircle(vararrayref(point),10.5); //画圆
end;
end. |
|