徐
徐辰仲
Unregistered / Unconfirmed
GUEST, unregistred user!
unit helloworld;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,comOBJ,ActiveX;//一定要加入ComObj,ActiveX两个单元
type
ThelloForm = class(TForm)
Edit1: TEdit;
Button1: TButton;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
Mpath:string;
AcadApp,AcadDoc,AcadMS:OleVariant; //定义Acad应用对象,当前图纸文件,模型空间
end;
var
helloForm: ThelloForm;
implementation
{$R *.dfm}
procedure ThelloForm.FormCreate(Sender: TObject);
begin
try
AcadApp:= GetActiveOleObject('AutoCad.Application'); //取得当前打开的autocad对象
except
AcadApp:=CreateOleObject('AutoCad.Application'); //没有创建新的autocad对象
end;
AcadDoc:=AcadApp.ActiveDocument; //当前图纸文件
AcadMS:=AcadDoc.ModelSpace; //模型空间
Mpath:=ExtractFilePath(Application.ExeName);//获取主文件路径
end;
procedure ThelloForm.Button1Click(Sender: TObject);
var
insPoint:Variant;
textHeight:integer;
textStr:string;
begin
insPoint:=VarArrayCreate([0,2],VT_R8); //定义插入点 (维数,类型)VT_8代表8字节的实型数
insPoint[0]:=2.0; //定义插入点X坐标
insPoint[1]:=4.0; //定义插入点Y坐标
insPoint[2]:=0.0; //定义插入点Z坐标
textHeight:=50;//文本高度
textStr:='Hello World!';//插入的文本字符
edit1.text:='Hello World!';
AcadApp.Visible:=True; //打开Autocad,使之可见
AcadMS.addText(textStr,varArrayRef(insPoint),textHeight);//将定义好的文本插入模型空间(文本,点指针,高度)
AcadDoc.SaveAS(Mpath+'hello.dwg'); //保存文件
end;
编译后会出现First chance exception at $7C81EB33. Exception class EOleSysError with message '操作无法使用'. Process hello.exe (2964)的错误,麻烦各位了!
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,comOBJ,ActiveX;//一定要加入ComObj,ActiveX两个单元
type
ThelloForm = class(TForm)
Edit1: TEdit;
Button1: TButton;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
Mpath:string;
AcadApp,AcadDoc,AcadMS:OleVariant; //定义Acad应用对象,当前图纸文件,模型空间
end;
var
helloForm: ThelloForm;
implementation
{$R *.dfm}
procedure ThelloForm.FormCreate(Sender: TObject);
begin
try
AcadApp:= GetActiveOleObject('AutoCad.Application'); //取得当前打开的autocad对象
except
AcadApp:=CreateOleObject('AutoCad.Application'); //没有创建新的autocad对象
end;
AcadDoc:=AcadApp.ActiveDocument; //当前图纸文件
AcadMS:=AcadDoc.ModelSpace; //模型空间
Mpath:=ExtractFilePath(Application.ExeName);//获取主文件路径
end;
procedure ThelloForm.Button1Click(Sender: TObject);
var
insPoint:Variant;
textHeight:integer;
textStr:string;
begin
insPoint:=VarArrayCreate([0,2],VT_R8); //定义插入点 (维数,类型)VT_8代表8字节的实型数
insPoint[0]:=2.0; //定义插入点X坐标
insPoint[1]:=4.0; //定义插入点Y坐标
insPoint[2]:=0.0; //定义插入点Z坐标
textHeight:=50;//文本高度
textStr:='Hello World!';//插入的文本字符
edit1.text:='Hello World!';
AcadApp.Visible:=True; //打开Autocad,使之可见
AcadMS.addText(textStr,varArrayRef(insPoint),textHeight);//将定义好的文本插入模型空间(文本,点指针,高度)
AcadDoc.SaveAS(Mpath+'hello.dwg'); //保存文件
end;
编译后会出现First chance exception at $7C81EB33. Exception class EOleSysError with message '操作无法使用'. Process hello.exe (2964)的错误,麻烦各位了!