Code sample Home

Modify values of attribute "NUM" in all references of the block "KM", created by the code sample
void DemoBlockAttEdit2 (HANDLE hLcWnd)
{
  HANDLE hDrw, hBlock, hBlock2, hEnt, hAtt;
  int i;
  WCHAR* szBlockName = L"KM";
  WCHAR* szTag = L"NUM";
  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 );

  // unselect all entities
  lcBlockUnselect( hBlock );
  // find required block
  hBlock2 = lcDrwGetObjectByName( hDrw, LC_OBJ_BLOCK, szBlockName );
  if (hBlock2 != 0){
    hEnt = lcBlockGetBlkRefByTag( hBlock, hBlock2, szTag, L"", true );
    if (hEnt){
      hEnt = lcBlockGetFirstSel( hBlock );
      while( hEnt != 0 ){
        hAtt = lcBlkRefGetAtt( hEnt, szTag );
        if (hAtt != 0){
          // get attribute value
          wcsncpy( szValue, lcPropGetStr( hAtt, LC_PROP_ATT_VALUE ), 250 );
          i = _wtoi( szValue );
          ++i;
          // set attribute value
          _itow( i, szValue, 10 );
          lcPropPutStr( hAtt, LC_PROP_ATT_VALUE, szValue );
        }
        hEnt = lcBlockGetNextSel( hBlock );
      }
    }
    // unselect all entities
    lcBlockUnselect( hBlock );
    // redraw window
    lcWndRedraw( hLcWnd );
  }
}
After several calls of this function the drawing will looks like this:



See Also:

Another variant to find block references