- UID
- 5043
- 积分
- 1347
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-5-13
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
Here is a sample ObjectARX code to demonstrate the usage of InsertBlock method of the AutoCAD 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[500];
- drawingFilePath[0] = _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;
- 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);
- }
|
|