Code sample Home

Create shape entity filled with lines. Then retrieve the filling lines. Subsequent function calls will create different drawings (3 variants).
//-----------------------------------------------
void DemoExpShapeLinfill (HANDLE hLcWnd)
{
  static int Step = 0;

  HANDLE hDrw, hBlock, hTStyle, hFill, hEnt, hShape;
  double x, y, Ht, bsz, X, Y, X2, Y2, dx;
  WCHAR* szTStyleName;
  WCHAR* szFillName;
  BOOL   bOK, bSolidFill;
  int    Key, K, FillColor, nPlines, i, nVers;
  double X0, Y0, W, H, HatchDensity, HatchAngle;
  WCHAR  szText[64], szQRtext[64];

  bSolidFill = false;
  FillColor = lcColorRGB( 120, 220, 255 );

  // input data
  X0 = 0.0;
  Y0 = 0.0;
  W = 40.0;
  H = 30.0;
  switch( Step ){
    case 0: 
      wcscpy( szText, L"PROVA" );
      break;
    case 1: 
      wcscpy( szText, L"AVITO" );
      break;
    case 2: 
      wcscpy( szText, L"QWERT" );
      break;
  }
  wcscpy( szQRtext, szText );
  HatchDensity = 0.1;  // distance between filling lines
  HatchAngle = 0.0 * LC_DEG_TO_RAD;  // angle of filling lines (radians)
  ++Step;
  if (Step == 3){
    Step = 0;
  }

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

  // add text style, if not exist
  szTStyleName = L"Title";
  hTStyle = lcDrwGetObjectByName( hDrw, LC_OBJ_TEXTSTYLE, szTStyleName );
  if (hTStyle == NULL){
    hTStyle = lcDrwAddTextStyle( hDrw, szTStyleName, L"Arial", true );
    if (hTStyle != 0){
      // make this text style active
      lcPropPutHandle( hDrw, LC_PROP_DRW_TEXTSTYLE, hTStyle );
    }
  }

  if (bSolidFill == false){
    // add linfill style, if not exist
    szFillName = L"Hatch 1";
    hFill = lcDrwGetObjectByName( hDrw, LC_OBJ_LINFILL, szFillName );
    if (hFill == NULL){
      hFill = lcDrwAddFilling( hDrw, szFillName );
      if (hFill != 0){
        // define the hatch lines
        lcFillSetLine( hFill, 0, HatchDensity, HatchAngle, 0.0 );
      }
    }
  }

  lcBlockClear( hBlock, NULL );
  lcPropPutStr( hDrw, LC_PROP_DRW_COLOR, L"foreground" );
  Key = 123;  // used to mark entities that will make a shape

  // add rectangle
  hEnt = lcBlockAddRect2( hBlock, X0, Y0, W, H, 0.0, false );
  lcPropPutInt( hEnt, LC_PROP_ENT_KEY, Key );

  // add text and explode it to polylines
  x = X0 + W/2.0;
  y = Y0 + H/15.0;
  Ht = H / 5.0;
  hEnt = lcBlockAddText2( hBlock, szText, x, y, LC_TA_CENBOT, Ht, 1.0, 0.0, 0.0 );
  if (lcEntExplode( hEnt, true, true ) == TRUE){
    // mark the entities which are result of the explode
    hEnt = lcBlockGetFirstSel( hBlock );
    while( hEnt != 0){
      lcPropPutInt( hEnt, LC_PROP_ENT_KEY, Key );
      hEnt = lcBlockGetNextSel( hBlock );
    }
    lcBlockUnselect( hBlock );
  }else{
    // fail
    return;
  }

  // add barcode and explode it to polylines
  x = X0 + W*0.3;
  y = Y0 + H*0.65;
  bsz = H * 0.6;
  hEnt = lcBlockAddBarcode( hBlock, LC_BARTYPE_MQR, x, y, bsz, bsz, szQRtext );
  if (lcEntExplode( hEnt, true, true ) == TRUE){
    // mark the entities which are result of the explode
    hEnt = lcBlockGetFirstSel( hBlock );
    while( hEnt != 0){
      lcPropPutInt( hEnt, LC_PROP_ENT_KEY, Key );
      hEnt = lcBlockGetNextSel( hBlock );
    }
    lcBlockUnselect( hBlock );
  }else{
    // fail
    return;
  }

  // create shape from marked entities
  hShape = lcBlockAddShape( hBlock );
  hEnt = lcBlockGetFirstEnt( hBlock );
  while (hEnt != 0){
    K = lcPropGetInt( hEnt, LC_PROP_ENT_KEY );
    if (K == Key){
      lcShapeAddEnt( hShape, hEnt, true );
    }
    hEnt = lcBlockGetNextEnt( hBlock, hEnt );
  }
  bOK = lcShapeEnd( hShape );

  if (bOK){
    if (bSolidFill){
      // use this code for solid fill
      lcPropPutBool( hShape, LC_PROP_ENT_SOLIDFILL, true );
      lcPropPutInt( hShape, LC_PROP_ENT_FCOLOR, FillColor );
    }else{
      // fill the shape with lines
      lcPropPutHandle( hShape, LC_PROP_ENT_LINFILL, hFill );
      // get the filling lines
      nPlines = lcExpEntity( hShape, -1, LC_EXP_HATCH, false );
      if (nPlines > 0){
        dx = W * 1.05;  // offset value
        lcPropPutInt( hDrw, LC_PROP_DRW_COLOR, FillColor );
        for (i=0; i<nPlines; ++i){
          nVers = lcExpGetPline( 0.0 );
          if (nVers == 2){
            lcExpGetVertex( &X, &Y );
            lcExpGetVertex( &X2, &Y2 );
            // offset the lines to the right side of the rectangle
            X = X + dx;
            X2 = X2 + dx;
            lcBlockAddLine( hBlock, X, Y, X2, Y2 );
          }
        }
      }
    }
  }else{
    // fail
    return;
  }

  // zoom extents
  lcWndZoomRect( hLcWnd, 0, 0, 0, 0 );
  lcWndZoomScale( hLcWnd, 0.95 );
}
This will create a drawing as shown on the picture below:



Zoomed parts:






See Also:

Retrieve vertices and lines of filled text
Retrieve vertices of entity's outlines (circle)
Retrieve vertices of entity's hatch lines (barcode)