得到选择的图块个数.
C++开发|大少爷|2017-07-27 15:44
-
回答:
using namespace MxDrawXLib; void CTestDynCreateDlg::DoSelectBlk() { IMxDrawUtilityPtr utility; utility.CreateInstance(__uuidof( MxDrawUtility )); if(utility == NULL) { return; } _variant_t varPrompt; V_VT(&varPrompt) = VT_BSTR; CString sPrompt; sPrompt.Format(_T("选择一个实体:")); V_BSTR(&varPrompt) = sPrompt.AllocSysString(); _variant_t varSelPt; MxDrawXLib::IMxDrawEntityPtr spEnt = utility->GetEntity(&varSelPt,varPrompt); if(spEnt == NULL) return; CString sName((const char*)(spEnt->ObjectName) ); CComPtr<IMxDrawBlockReference> spBlk; spEnt->QueryInterface(&spBlk); if(spBlk == NULL) { return; } CString sBlkName = spBlk->GetBlockName(); MxDrawXLib::IMxDrawSelectionSetPtr ssGet; ssGet.CreateInstance(__uuidof( MxDrawXLib::MxDrawSelectionSet )); if(ssGet == NULL) { return; } MxDrawXLib::IMxDrawResbufPtr filter; filter.CreateInstance(__uuidof( MxDrawXLib::MxDrawResbuf )); // 设置图块 filter->AddString(_T("INSERT"),5020); _bstr_t blkName((LPCTSTR)sBlkName); filter->AddString(blkName,2); std::auto_ptr<_variant_t> spVarPt1(new _variant_t); std::auto_ptr<_variant_t> spVarPt2(new _variant_t); ssGet->Select2(mcSelectionSetAll,*spVarPt1.get(),*spVarPt2.get(),NULL,filter); if(ssGet->GetCount() == 0) return; // for(long i = 0; i < ssGet->GetCount();i++) // { // MxDrawXLib::IMxDrawEntityPtr spEnt = ssGet->Item(i); // if(spEnt == NULL) // continue; // } CString sT; sT.Format(_T("发现了%d个"), ssGet->GetCount()); AfxMessageBox(sT); }