void DemoDelEntsByLayer (HANDLE hLcWnd, LPCWSTR szLayerName)
{
HANDLE hLcDrw, hBlock, hEnt, hLayer, hEntLayer;
int nDel;
// get drawing and block linked with the window
hLcDrw = lcPropGetHandle( hLcWnd, LC_PROP_WND_DRW );
hBlock = lcPropGetHandle( hLcWnd, LC_PROP_WND_VIEWBLOCK );
// get layer handle by name
hLayer = lcDrwGetObjectByName( hLcDrw, LC_OBJ_LAYER, szLayerName );
if (hLayer == 0){
// can not find a layer with the name
return;
}
// enumerate blocks of the drawing
hBlock = lcDrwGetFirstObject( hLcDrw, LC_OBJ_BLOCK );
while( hBlock!=0 ){
nDel = 0; // counter of deleted entities
// enumerate entities of the block
hEnt = lcBlockGetFirstEnt( hBlock );
while( hEnt!=0 ){
// get handle of entity's layer
hEntLayer = lcPropGetHandle( hEnt, LC_PROP_ENT_LAYER );
if (hEntLayer == hLayer){
lcEntErase( hEnt, true );
++nDel;
}
hEnt = lcBlockGetNextEnt( hBlock, hEnt );
}
if (nDel > 0){
lcBlockUpdate( hBlock, true, 0 );
}
hBlock = lcDrwGetNextObject( hLcDrw, hBlock );
}
lcWndRedraw( hLcWnd );
}