找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 2397|回复: 0

[ARX程序]:运用COM编程启动AutoCAD 并创建选择集合

[复制链接]
发表于 2007-11-21 13:23:27 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
#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);
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-11-22 00:31 , Processed in 0.176612 second(s), 31 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表