|
实例代码:acedSSGet做选择的时候使用关键字(:K)
发表于 2014 年 11 月 13 日 由 boitboy
//-----------------------------------------------------------------------------
//----- acrxEntryPoint.cpp
//-----------------------------------------------------------------------------
#include "StdAfx.h"
#include "resource.h"
//-----------------------------------------------------------------------------
#define szRDS _RXST("")
//将ID数组转换为resbuf
void IdsToResbuf(struct resbuf*& rb,AcDbObjectIdArray& ids)
{
struct resbuf* rbEnd=rb;
Acad::ErrorStatus es=Acad::eOk;
for(int i=0;i<ids.logicalLength();i++)
{
ads_name ent;
es=acdbGetAdsName(ent,ids.at(i));
if(es!=Acad::eOk)
{
continue;
}
if(rbEnd==NULL)
{
rb=acutBuildList(RTENAME,ent,0);
rbEnd=rb;
}
else if(rbEnd!=NULL)
{
rbEnd->rbnext=acutBuildList(RTENAME,ent,0);
rbEnd=rbEnd->rbnext;
}
}
}
//获取所有的块参照
Acad::ErrorStatus GetAllBREF(AcDbObjectIdArray& ids,AcDbBlockTableRecord* pRecord)
{
if(pRecord==NULL)
{
return Acad::eNullPtr;
}
AcDbBlockTableRecordIterator* pIterator=NULL;
Acad::ErrorStatus es=pRecord->newIterator(pIterator);
if(es!=Acad::eOk)
{
return es;
}
//用std::auto_ptr包装,尽量不直接暴露指针
std::auto_ptr<AcDbBlockTableRecordIterator> spIterator(pIterator);
for(spIterator->start();!spIterator->done();spIterator->step())
{
AcDbEntity* pEntity=NULL;
es=spIterator->getEntity(pEntity,AcDb::kForRead);
if(es!=Acad::eOk)
{
continue;
}
AcDbEntityPointer spEnt;
//用AcDbEntityPointer包装,防止忘记close导致的CAD崩溃
spEnt.acquire(pEntity);
if(!spEnt->isKindOf(AcDbBlockReference::desc()))
{
continue;
}
ids.append(spEnt->objectId());
}
return Acad::eOk;
}
//获取所有的块参照
Acad::ErrorStatus GetAllBREF(AcDbObjectIdArray& ids)
{
AcDbDatabase* pDb=acdbHostApplicationServices()->workingDatabase();
if(pDb==NULL)
{
return Acad::eNullPtr;
}
//打开块表
AcDbBlockTablePointer spRec(pDb->blockTableId(),AcDb::kForRead);
if(spRec.openStatus()!=Acad::eOk)
{
return spRec.openStatus();
}
AcDbBlockTableIterator* pIterator=NULL;
//新建遍历器
Acad::ErrorStatus es=spRec->newIterator(pIterator);
if(es!=Acad::eOk)
{
return es;
}
//用std::auto_ptr包装,尽量不直接暴露指针
std::auto_ptr<AcDbBlockTableIterator> spIterator(pIterator);
for(spIterator->start();!spIterator->done();spIterator->step())
{
AcDbBlockTableRecord* pRecord=NULL;
es=spIterator->getRecord(pRecord,AcDb::kForRead);
if(es!=Acad::eOk)
{
continue;
}
GetAllBREF(ids,pRecord);
//记住一定要关闭
pRecord->close();
}
return Acad::eOk;
}
resbuf* ssCallback(const TCHAR* kword)
{
if(lstrcmpi(kword,_T("Q"))==0)
{
AcDbObjectIdArray ids;
resbuf* rb=NULL;
GetAllBREF(ids);
IdsToResbuf(rb,ids);
return rb;
}
else if(lstrcmpi(kword,_T("ER"))==0)
{
return acutBuildList(RTSTR,_T("发生错误!"),0);
}
else if(lstrcmpi(kword,_T("JX"))==0)
{
AfxMessageBox(_T("完成一些工作后,继续执行选择操作"));
return NULL;
}
else
{
return acutBuildList(RTSTR,_T("暂时不支持的关键字!"),0);
}
}
void Test()
{
resbuf* (*oldFunc) (const ACHAR*);
acedSSGetKwordCallbackPtr(&oldFunc);
acedSSSetKwordCallbackPtr(ssCallback);
//过滤器,只选择快参照
resbuf* rb = acutBuildList(RTDXF0, _T("INSERT"), 0);
ads_name ssName;
//口(W)/上一个(L)/窗交(C)/框(BOX)/全部(ALL)/栏选(F)/圈围(WP)/圈交(CP)/编组(G)/添加(A)/删除(R)/多个(M)/前一个(P)/放弃(U)/自动(AU)/单个(SI)
//已经被使用了,不可以再使用
TCHAR* promptPtrs[2]={_T("\n选择块[全图(Q)/错误(ER)/继续(JX)]:"),_T("\n移除块:")};
acedInitGet(RSG_NONULL,_T("Q ER JX"));
ACHAR kwordlist[] = { _T("Q ER JX _ Q ER JX") };
int rc=acedSSGet(_T(":$:K"), promptPtrs,kwordlist,rb,ssName);
if(rc!=RTNORM)
{
acutRelRb(rb);
acedSSSetKwordCallbackPtr(*oldFunc);
return;
}
acutRelRb(rb);
acedSSSetKwordCallbackPtr(*oldFunc);
}
//-----------------------------------------------------------------------------
//----- ObjectARX EntryPoint
class CExample001App : public AcRxArxApp {
public:
CExample001App () : AcRxArxApp () {}
virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt) {
// TODO: Load dependencies here
// You *must* call On_kInitAppMsg here
AcRx::AppRetCode retCode =AcRxArxApp::On_kInitAppMsg (pkt) ;
//增加命令Test
acedRegCmds->addCommand(_T("Example001App"),_T("Test"),_T("Test"),0,Test);
// TODO: Add your initialization code here
return (retCode) ;
}
virtual AcRx::AppRetCode On_kUnloadAppMsg (void *pkt) {
// TODO: Add your code here
// You *must* call On_kUnloadAppMsg here
AcRx::AppRetCode retCode =AcRxArxApp::On_kUnloadAppMsg (pkt) ;
// TODO: Unload dependencies here
//删除命令组
acedRegCmds->removeGroup(_T("Example001App"));
return (retCode) ;
}
virtual void RegisterServerComponents () {
}
} ;
//-----------------------------------------------------------------------------
IMPLEMENT_ARX_ENTRYPOINT(CExample001App) |
|