Code sample Home

Get an array of coordinates of point entities on specific layer.
void DemoGetPoints2 (HANDLE hLcWnd)
{
  WCHAR*  szLayerName = L"Cool Points";
  HANDLE  hDrw, hBlock, hLayer, hEnt, hEntLayer, hPline;
  int     EntType, i;
  int     nPnts = 0;
  double* X = NULL;
  double* Y = NULL;
  
  // get drawing and block, linked with CAD window
  hDrw = lcPropGetHandle( hLcWnd, LC_PROP_WND_DRW );
  hBlock = lcPropGetHandle( hLcWnd, LC_PROP_WND_BLOCK );

  // check if the layer with specified name exist
  hLayer = lcDrwGetObjectByName( hDrw, LC_OBJ_LAYER, szLayerName );
  if (hLayer == 0){
    // not exist
    return;
  }

  // count points on the layer
  hEnt = lcBlockGetFirstEnt( hBlock );
  while( hEnt != 0 ){
    EntType = lcPropGetInt( hEnt, LC_PROP_ENT_TYPE );
    if (EntType == LC_ENT_POINT){
      hEntLayer = lcPropGetHandle( hEnt, LC_PROP_ENT_LAYER );
      if (hEntLayer == hLayer){
        ++nPnts;
      }
    }
    hEnt = lcBlockGetNextEnt( hBlock, hEnt );
  }
  if (nPnts == 0){
    // no points on the specified layer
    return;
  }

  // allocate memory for the array of points coordinates
  X = new double[nPnts];
  Y = new double[nPnts];
  i = 0;

  // fill the X,Y array
  hEnt = lcBlockGetFirstEnt( hBlock );
  while( hEnt != 0 ){
    EntType = lcPropGetInt( hEnt, LC_PROP_ENT_TYPE );
    if (EntType == LC_ENT_POINT){
      hEntLayer = lcPropGetHandle( hEnt, LC_PROP_ENT_LAYER );
      if (hEntLayer == hLayer){
        X[i] = lcPropGetFloat( hEnt, LC_PROP_POINT_X );
        Y[i] = lcPropGetFloat( hEnt, LC_PROP_POINT_Y );
        ++i;
      }
    }
    hEnt = lcBlockGetNextEnt( hBlock, hEnt );
  }

  // do something with the array ...
  hPline = lcBlockAddPolyline( hBlock, 0, false, false );
  for (i=0; i<nPnts; ++i){
    lcPlineAddVer( hPline, 0, X[i], Y[i] );
  }
  lcPlineEnd( hPline );
  // update and display
  lcBlockUpdate( hBlock, true, 0 );
  lcWndExeCommand( hLcWnd, LC_CMD_ZOOM_EXT, 0 );

  // free the X,Y array
  delete[] X;
  delete[] Y;
}
Used functions:

lcDrwGetObjectByName
lcBlockGetFirstEnt
lcBlockGetNextEnt

lcPropGetFloat
lcPropGetHandle

lcBlockAddPolyline
lcPlineAddVer
lcPlineEnd

lcBlockUpdate
lcWndExeCommand