Code sample Home

Create a block with "ByBlock" color and insert it into a drawing using various colors
void DemoBlockColor (HANDLE hLcWnd)
{
  HANDLE hDrw, hTStyle, hBlock, hBlock2, hBlkRef, hPline, hText;
  WCHAR* szBlockName = L"RGB";
  WCHAR* szTStyleName = L"RGB";
  double X0, Y0, X, Y, Ang, Dist, AngStep;
  int    i;
  int    Color[8] = {RGB(255,0,0), RGB(0,255,0), RGB(0,0,255), RGB(0,255,255), 
                     RGB(255,0,255), RGB(255,255,0), RGB(128,50,200), RGB(200,50,128)} ;

  // get drawing and block, linked with CAD window
  hDrw = lcPropGetHandle( hLcWnd, LC_PROP_WND_DRW );
  hBlock = lcPropGetHandle( hLcWnd, LC_PROP_WND_BLOCK );
  // get a text style with specified name
  hTStyle = lcDrwGetObjectByName( hDrw, LC_OBJ_TEXTSTYLE, szTStyleName );
  if (hTStyle == NULL){
    // the style don't exist, create it
    hTStyle = lcDrwAddTextStyle( hDrw, szTStyleName, L"Arial", true );
  }
  // set active text style
  lcPropPutHandle( hDrw, LC_PROP_DRW_TEXTSTYLE, hTStyle );
  // get a block with specified name
  hBlock2 = lcDrwGetObjectByName( hDrw, LC_OBJ_BLOCK, szBlockName );
  if (hBlock2 == NULL){
    // the block don't exist, create it
    hBlock2 = lcDrwAddBlock( hDrw, szBlockName, 0, 0 );
    // add filled polygon
    hPline = lcBlockAddPolyline( hBlock2, 0, true, true );
    lcPlineAddVer( hPline, 0, -5, 0 );
    lcPlineAddVer( hPline, 0, -5, 5 );
    lcPlineAddVer( hPline, 0, 5, 5 );
    lcPlineAddVer( hPline, 0, 5, 0 );
    lcPlineAddVer( hPline, 0, 3, -2 );
    lcPlineAddVer( hPline, 0, -3, -2 );
    lcPlineEnd( hPline );
    // set filling color
    lcPropPutInt( hPline, LC_PROP_ENT_FCOLOR, RGB(128,128,128) );
    // disable outline
    lcPropPutInt( hPline, LC_PROP_ENT_LWIDTH, 0 );
    // add text inside the polygon
    hText = lcBlockAddText2( hBlock2, L"RGB", 0,2.3, LC_TA_CENTER, 3.0, 0, 0, 0 );
    // set the text color "ByBlock"
    lcPropPutInt( hText, LC_PROP_ENT_COLORI, LC_COLOR_BYBLOCK );
    // update extents
    lcBlockUpdate( hBlock2, true, 0 );
  }
  // add the block references
  X0 = 50.0;
  Y0 = 30.0;
  Dist = 15.0;
  Ang = 0.0;
  AngStep = LC_DEG45;  // 360 / 8 = 45
  for (i=0; i<8; ++i){
    lcGetPolarPoint( X0, Y0, Ang, Dist, &X, &Y );
    hBlkRef = lcBlockAddBlockRef( hBlock, hBlock2, X, Y, 1, Ang-LC_DEG90 );
    // next position
    Ang += AngStep;
    // set separate color for each BlockRef
    lcPropPutInt( hBlkRef, LC_PROP_ENT_COLOR, Color[i] );
  }
  // display
  lcBlockUpdate( hBlock, true, 0 );
  Dist = Dist * 1.5;
  lcWndZoomRect( hLcWnd, X0-Dist, Y0-Dist, X0+Dist, Y0+Dist );
}
This will create a drawing as shown on the picture below: