C++ Builder 连接AutoCAD画图出错,求帮助
首先是打开AutoCAD,这个没问题,代码如下:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Variant CAD;
try
{
CAD=CreateOleObject("AutoCAD.Application");
CAD.OlePropertySet("Visible",true);
}
catch (...)
{ShowMessage("AutoCAD启动失败");}
}
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Variant CAD,obj1,obj2;
Variant pt1,pt2;
double tmp;
pt1=VarArrayCreate(OPENARRAY(int,(0,2)),varDouble);
tmp=30.0;
pt1.PutElement(&tmp,0);
tmp=3.5;
pt1.PutElement(&tmp,1);
tmp=0.0;
pt1.PutElement(&tmp,2);
pt2=VarArrayCreate(OPENARRAY(int,(0,2)),varDouble);
tmp=70.0;
pt2.PutElement(&tmp,0);
tmp=30.0;
pt2.PutElement(&tmp,1);
tmp=0.0;
pt2.PutElement(&tmp,2);
CAD=GetActiveOleObject("AutoCAD.Application");
obj1=CAD.OleFunction("ActiveDocument");
obj2=obj1.OleFunction("ModelSpace");
obj2.OleProcedure("AddLine",VarArrayRef(pt1),VarArrayRef(pt2));
}
obj1 = CAD.OlePropertyGet("ActiveDocument");