- UID
- 239519
- 积分
- 0
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2005-4-7
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
#import "acax17enu.tlb" raw_interfaces_only no_namespace named_guids rename("GetObject", "acaxGetObject")
IAcadApplicationPtr m_pAcadApp;
//Start AutoCAD
HRESULT hr = NOERROR;
if(FAILED(m_pAcadApp.GetActiveObject(L"AutoCAD.Application")))
{
if(FAILED(m_pAcadApp.CreateInstance(L"AutoCAD.Application")))
{
AfxMessageBox(_T("Failed to get or start Acad."), MB_ICONEXCLAMATION);
return;
}
}
if(m_pAcadApp.GetInterfacePtr() == NULL)
return;
m_pAcadApp->put_Visible(VARIANT_TRUE);// you can put it invisible
m_pAcadApp->AddRef();
// Get IAcadDocuments interface.
CComPtr<IAcadDocuments> pDocs;
hr = m_pAcadApp->get_Documents(&pDocs);
if(FAILED(hr))
return;
// open one drawing
CComBSTR fileName("c:\\test.dwg");
CComVariant b(VARIANT_FALSE, VT_BOOL);
CComVariant vStr("");
// Open a drawing, c:\test.dwg.
CComPtr<IAcadDocument> pDoc;
hr = pDocs->Open(fileName, b, vStr, &pDoc);
if(FAILED(hr))
return;
CComPtr<IAcadSelectionSets> pSelSets;
// Get the selection Set collection
hr=pDoc->get_SelectionSets(&pSelSets);
CComPtr<IAcadSelectionSet> pSelSet;
hr = pSelSets->Add(CComBSTR("Test"),&pSelSet);
SAFEARRAY *aGrpCodes=NULL;
SAFEARRAY *aGrpVals=NULL;
SAFEARRAYBOUND bnd;
bnd.lLbound = 0;
bnd.cElements =1;
VARIANT vGrpCode, vGrpVal;
aGrpCodes = SafeArrayCreate(VT_I2, 1, &bnd);
long i = 0;
long code = 0;
SafeArrayPutElement(aGrpCodes, &i, &code);
vGrpCode.vt = VT_I2 | VT_ARRAY;
vGrpCode.parray = aGrpCodes;
// Add the filter
CComBSTR grname = ("CIRCLE") ;
VARIANT vtStr;
vtStr.vt = VT_BSTR;
vtStr.bstrVal = grname;
aGrpVals = SafeArrayCreate(VT_VARIANT, 1, &bnd);
SafeArrayPutElement(aGrpVals, &i, &vtStr);
vGrpVal.vt = VT_VARIANT | VT_ARRAY;
vGrpVal.parray = aGrpVals;
// define optional variant argument
VARIANT vopt;
VariantInit(&vopt);
V_VT(&vopt) = VT_ERROR;
vopt.scode = DISP_E_PARAMNOTFOUND;
hr = pSelSet->Select(acSelectionSetAll,vopt ,vopt,vGrpCode,vGrpVal);
// Get the count
long iCnt = 0;
hr=pSelSet->get_Count(&iCnt);
CString strTmp;
strTmp = "Have get the current selection set";
AfxMessageBox(LPCTSTR(strTmp));
pSelSet->Delete();
SafeArrayDestroy(aGrpCodes);
SafeArrayDestroy(aGrpVals); |
|