在Qt中利用COM输出.dwg格式的CAD文件,但是使用需要传递点数据的函数时出现错误,其他函数正常。AutoCAD的VBA帮助文档中点数据为three-element array of doubles。
(1)如下:
QAxObject * cad=new QAxObject(this);
cad->setControl("AutoCAD.Application");
cad->setProperty("Visible",true);
QAxObject * documents=cad->querySubObject("Documents");
//打开已存在的一个.dwg文件
QAxObject * document=documents-
>querySubObject("Open(QString)",absolutefileName);
//定义点数据
QList<QVariant> startP;
QList<QVariant> endP;
startP<<0<<0<<0;
endP<<200<<200<<0;
QVariantList pointList;
pointList<<QVariant(startP)<<QVariant(endP);
//调用AddLine函数画一条线
QAxObject * space=document->querySubObject("ModelSpace");
space->querySubObject("AddLine(QVariant,QVariant)",pointList);
(2)错误提示:
QAxBase: Error calling IDispatch member AddLine: Exception thrown by server
Code : 87
Source :
Description:
Help :
Connect to the exception(int,QString,QString,QString) signal to catch this exception
(3)COM的“AddLine”说明:
IDispatch* AddLine (QVariant StartPoint, QVariant EndPoint) [slot]
Connect a signal to this slot:
QObject::connect(sender, SIGNAL(someSignal(QVariant, QVariant)),object, SLOT(AddLine(QVariant,
QVariant)));
Or call the function directly:
QVariantList params = ...
QAxObject * result = object->querySubObject("AddLine(QVariant, QVariant)", params);
(4)AutoCAD中关于相应的VBA函数格式的说明:
Signature
RetVal = object.AddLine(StartPoint, EndPoint)
Object
ModelSpace Collection, PaperSpace Collection, Block
The objects this method applies to.
StartPoint
Variant (three-element array of doubles); input-only
The 3D WCS coordinates specifying the line start point.
EndPoint
Variant (three-element array of doubles); input-only
The 3D WCS coordinates specifying the line endpoint.
RetVal
Line object
The newly created Line object.