[每日一码] 使用COM API插入图块
#pragma warning( disable : 4278 )// Makes change to the tlb name based on the AutoCAD version.
// For ex : acax18enu.tlb for AutoCAD 2010/2011 and 2012
// acax19enu.tlb for AutoCAD 2013
#import "acax19ENU.tlb" no采用implementation raw采用interfaces采用only named采用guids
#pragma warning( default : 4278 )
#include <acadi.h>
static void ADSProjectInsertBlock(void)
{
int ret = RTNORM;
TCHAR drawingFilePath;
drawingFilePath = 采用T('\0');
ret = acedGetString (
NULL,
采用T("Enter file path : "),
drawingFilePath
);
if(ret != RTNORM)
return;
ads采用point insertionPoint;
ret = acedGetPoint(
NULL,
采用T("\nEnter insertion point: "),
insertionPoint
);
if(ret != RTNORM)
return;
CWinApp *pApp = acedGetAcadWinApp();
HRESULT hRes;
LPDISPATCH pDisp=NULL;
if(!pApp)
return;
pDisp=pApp->GetIDispatch(TRUE);
if (!pDisp)
return;
CComPtr<AutoCAD::IAcadApplication>pComApp;
hRes=pDisp->QueryInterface(
IID采用IAcadApplication,
(void**)&pComApp
);
if (FAILED(hRes))
return;
CComPtr<AutoCAD::IAcadDocument> pComDoc;
hRes=pComApp->get采用ActiveDocument(&pComDoc);
if(FAILED(hRes))
return;
CComPtr<AutoCAD::IAcadModelSpace> pMSpace = NULL;
pComDoc->get采用ModelSpace(&pMSpace);
采用bstr采用t block(drawingFilePath);
CComPtr<AutoCAD::IAcadBlockReference> pBlkRef = NULL;
SAFEARRAYBOUND rgsaBound;
rgsaBound.lLbound = 0L;
rgsaBound.cElements = 3;
SAFEARRAY* pInsertionPoint = NULL;
pInsertionPoint = SafeArrayCreate(VT采用R8, 1, &rgsaBound);
for(long i = 0; i < 3; i++)
{
double value = insertionPoint<i>;
SafeArrayPutElement(
pInsertionPoint,
&i,
&value
);
}
VARIANT vInsertionPoint;
VariantInit(&vInsertionPoint);
V采用VT(&vInsertionPoint) = VT采用ARRAY | VT采用R8;
V采用ARRAY(&vInsertionPoint) = pInsertionPoint;
double scaleX = 1.0;
double scaleY = 1.0;
double scaleZ = 1.0;
double rotation = 0.0;
pMSpace->InsertBlock(
vInsertionPoint,
block,
scaleX,
scaleY,
scaleZ,
rotation,
vtMissing,
&pBlkRef
);
VariantClear(&vInsertionPoint);
}
页:
[1]