Code sample Home

Enumerate layers

void DemoEnumLayers (HANDLE hLcWnd)
{
  HANDLE hDrw, hLayer;
  WCHAR  szBuf[256];
  int    N, iColor, R, G, B;
  BOOL   bVisible, bIndexColor, bRGB; 
  COLORREF TrueColor;

  // get a drawing, linked with CAD window
  hDrw = lcPropGetHandle( hLcWnd, LC_PROP_WND_DRW );
  // get number of layers
  N = lcDrwCountObjects(  hDrw, LC_OBJ_LAYER );
  // get some properties of layers
  hLayer = lcDrwGetFirstObject( hDrw, LC_OBJ_LAYER );
  while( hLayer != 0 ){
    // layer name
    wcscpy( szBuf, lcPropGetStr( hLayer, LC_PROP_LAYER_NAME ));
    // visibility
    bVisible = lcPropGetBool( hLayer, LC_PROP_LAYER_VISIBLE );
    // color
    bIndexColor = lcPropGetBool( hLayer, LC_PROP_LAYER_COLORI );
    if (bIndexColor){
      // layer has indexed color
      iColor = lcPropGetInt( hLayer, LC_PROP_LAYER_COLORI );
      // get RGB values of the color index
      lcColorGetPalette( iColor, &R, &G, &B );
    }else{
      // layer has RGB color
      TrueColor = (COLORREF)lcPropGetInt( hLayer, LC_PROP_LAYER_COLORT );
    }
    // get color as text value
    wcscpy( szBuf, lcPropGetStr( hLayer, LC_PROP_LAYER_COLOR ));
    lcColorToVal( szBuf, &bRGB, &iColor, &R, &G, &B );
    // get next layer
    hLayer = lcDrwGetNextObject( hDrw, hLayer );
  }
}