Code sample Home

Create a block with attribute and insert it in into a drawing
void DemoBlockAttCreate (HANDLE hLcWnd)
{
  HANDLE hDrw, hBlock, hBlock2, hArc, hBlkRef;
  double x0, y0, x, y, H, R;
  WCHAR* szBlockName = L"KM";
  WCHAR* szTag1 = L"NUM";

  // get drawing and block, linked with CAD window
  hDrw = lcPropGetHandle( hLcWnd, LC_PROP_WND_DRW );
  hBlock = lcPropGetHandle( hLcWnd, LC_PROP_WND_BLOCK );

  // create new empty block
  x0 = y0 = 0.0;  // the block basepoint
  hBlock2 = lcDrwAddBlock( hDrw, szBlockName, x0, y0 );
  // add entities into the block
  H = 15.0;
  lcBlockAddLine( hBlock2, x0, y0, x0, y0-H );
  R = 2.5;
  y = y0 - H + R;
  lcBlockAddCircle( hBlock2, x0, y, R, false );
  hArc = lcBlockAddArc( hBlock2, x0, y, R, 90.0*LC_DEG_TO_RAD, -180.0*LC_DEG_TO_RAD );
  lcPropPutBool( hArc, LC_PROP_ARC_SECTOR, true );
  lcPropPutBool( hArc, LC_PROP_ENT_FILLED, true );
  lcPropPutInt( hArc, LC_PROP_ENT_FCOLORI, 7 );  // foreground color of the filling
  // add attribute definition into the block
  lcBlockAddAttDef( hBlock2, 0, szTag1, L"", L"0", x0+(R*1.5), y0-H, LC_TA_LEFBOT, R, 1.0, 0.0, 0.0 );
  lcBlockUpdate( hBlock2, true, 0 );

  // add entities into hBlock
  x = 100.0;
  y = 50.0;
  lcBlockAddLine( hBlock, x-15.0, y, x+65.0, y );
  // add the block references with different attributes
  hBlkRef = lcBlockAddBlockRef( hBlock, hBlock2, x, y, 1.0, 0.0 );
  lcBlkRefPutAttVal( hBlkRef, szTag1, L"13" );
  x += 25.0;
  hBlkRef = lcBlockAddBlockRef( hBlock, hBlock2, x, y, 1.0, 0.0 );
  lcBlkRefPutAttVal( hBlkRef, szTag1, L"14" );
  x += 25.0;
  hBlkRef = lcBlockAddBlockRef( hBlock, hBlock2, x, y, 1.0, 0.0 );
  lcBlkRefPutAttVal( hBlkRef, szTag1, L"15" );
  lcBlockUpdate( hBlock, true, 0 );
  
  // zoom extents
  lcWndExeCommand( hLcWnd, LC_CMD_ZOOM_EXT, 0 );
}
This will create a drawing as shown on the picture below:



See Also:

Add more attributes into a block
Modify attributes values in block references