Code sample Home

Modify values of block attributes created by the code samples
Create block with attribute
Add more attributes into a block
void DemoBlockAttEdit2 (HANDLE hLcWnd)
{
  HANDLE hDrw, hBlock, hBlock2, hRefBlock, hEnt;
  int    EntType;
  static int i=0;
  WCHAR* szBlockName = L"KM";
  WCHAR* szTag;
  WCHAR  szValue[256];

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

  // find required block
  hBlock2 = lcDrwGetObjectByName( hDrw, LC_OBJ_BLOCK, szBlockName );
  if (hBlock2 != 0){
    // enumerate entities
    hEnt = lcBlockGetFirstEnt( hBlock );
    while( hEnt != 0){
      EntType = lcPropGetInt( hEnt, LC_PROP_ENT_TYPE );
      if (EntType == LC_ENT_BLOCKREF){
        hRefBlock = lcPropGetHandle( hEnt, LC_PROP_BLKREF_BLOCK );
        if (hRefBlock == hBlock2){
          // This is a reference of block "KM"
          // Let's modify values of the block attributes
          szTag = L"NUM";
          wcscpy( szValue, lcBlkRefGetAttVal( hEnt, szTag ) );
          ++i;
          _itow( i, szValue, 10 );
          lcBlkRefPutAttVal( hEnt, szTag, szValue );
          szTag = L"LEFT";
          wcscpy( szValue, lcBlkRefGetAttVal( hEnt, szTag ) );
          ++i;
          _itow( i, szValue, 10 );
          lcBlkRefPutAttVal( hEnt, szTag, szValue );
          szTag = L"RIGHT";
          wcscpy( szValue, lcBlkRefGetAttVal( hEnt, szTag ) );
          ++i;
          _itow( i, szValue, 10 );
          lcBlkRefPutAttVal( hEnt, szTag, szValue );
        }
      }
      hEnt = lcBlockGetNextEnt( hBlock, hEnt );
    }
    // redraw window
    lcWndRedraw( hLcWnd );
  }
}
After several calls of this function the drawing will looks like this:



See Also:

Another variant to find block references