ObjectArx學習筆記-獲取某一圖層上所有直線
//-----------------------------------------------------------------------------
//----- acrxEntryPoint.h
//-----------------------------------------------------------------------------
#include "StdAfx.h"
#include "resource.h"
#include "dbsymtb.h"
//-----------------------------------------------------------------------------
#define szRDS _RXST("qxzy")
//-----------------------------------------------------------------------------
//----- ObjectARX EntryPoint
class CGetEntsOnLayerApp : public AcRxArxApp {
public:
CGetEntsOnLayerApp () : 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) ;
// 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
return (retCode) ;
}
virtual void RegisterServerComponents () {
}
public:
// - qxzyGetEntsOnLayer._GetEntsOnLayer command (do not rename)
static void qxzyGetEntsOnLayer_GetEntsOnLayer(void)
{
// Add your code for command qxzyGetEntsOnLayer._GetEntsOnLayer here
AcDbLayerTable *pLayerTbl;
acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pLayerTbl,AcDb::kForRead);
if(!pLayerTbl->has(_T("測試")))
{
acutPrintf(_T("\n當前圖形中未包含\"測試\"圖層!"));
pLayerTbl->close();
return;
}
AcDbObjectId layerId;
pLayerTbl->getAt(_T("測試"),layerId);
pLayerTbl->close();
AcDbBlockTable *pBlkTbl;
acdbHostApplicationServices()->workingDatabase()
->getBlockTable(pBlkTbl, AcDb::kForRead);
AcDbBlockTableRecord *pBlkTblRcd;
pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd, AcDb::kForRead);
pBlkTbl->close();
AcDbBlockTableRecordIterator *pltr;
pBlkTblRcd->newIterator(pltr);
AcDbEntity *pEnt;
for(pltr->start();!pltr->done();pltr->step())
{
pltr->getEntity(pEnt, AcDb::kForWrite);
if(pEnt->layerId() == layerId)
{
//whether it's a line
AcDbLine *pLine = AcDbLine::cast(pEnt);
if(pLine != NULL);
{
pLine->setColorIndex(1);
}
}
pEnt->close();
}
delete pltr;
pBlkTblRcd->close();
}
} ;
//-----------------------------------------------------------------------------
IMPLEMENT_ARX_ENTRYPOINT(CGetEntsOnLayerApp)
ACED_ARXCOMMAND_ENTRY_AUTO(CGetEntsOnLayerApp, qxzyGetEntsOnLayer, _GetEntsOnLayer, GetEntsOnLayer, ACRX_CMD_TRANSPARENT, NULL)
最後更新:2017-04-03 08:26:17