Code sample Home

Retrieve outlines of hatch entity

A sample drawing ("exp_hatch_2.lcd") has a hatch entity, marked with key value 123. We have to retrieve outlines of this hatch and create polylines which are copies of that outlines, with some offset

void DemoGetHatchOutlines (HANDLE hLcWnd)
  int    Key = 123;   // required hatch entity is marked with this key value
  HANDLE hBlock, hEntHatch, hPline;
  int    i, j, k, n, nPaths;
  double x, y, dx, dy;
  // get a block, linked with CAD window
  hBlock = lcPropGetHandle( hLcWnd, LC_PROP_WND_VIEWBLOCK );
  // get required hatch entity
  hEntHatch = lcBlockGetEntByKey( hBlock, Key );

  dx = 30.0;
  dy = 15.0;
  // get hatch outlines
  nPaths = lcPropGetInt( hEntHatch, LC_PROP_HATCH_NLOOP );
  k = 0;
  for (i=0; i<nPaths; ++i){
    // create a polyline which will be a copy of the hatch outline
    hPline = lcBlockAddPolyline( hBlock, 0, true, false );
    // get outline vertices
    n = lcHatchGetLoopSize( hEntHatch, i );
    for (j=0; j<n; ++j) {
      lcHatchGetPoint( hEntHatch, k, &x, &y );
      // add vertex to the polyline
      lcPlineAddVer( hPline, 0, x+dx, y+dy );
    lcPlineEnd( hPline );
    // set red color for the polyline
    lcPropPutInt( hPline, LC_PROP_ENT_COLOR, RGB(255,0,0) );
  lcBlockUpdate( hBlock, true, 0 );
  // view drawing's extents
  lcWndZoomRect( hLcWnd, 0, 0, 0, 0 );
This will create a drawing as shown on the picture below:

See Also:

Retrieve vertices of entity's hatch lines (barcode)
Retrieve boundary entities of hatch entity