Code sample Home

Using command LC_CMD_INSERT without dialog

void DemoCmdInsert (HANDLE hLcWnd)
{
  HANDLE hDrw, hBlock, hBlkRef;
  WCHAR* szBlockName = L"Block 007";
  double X, Y;

  // get the drawing linked with CAD window
  hDrw = lcPropGetHandle( hLcWnd, LC_PROP_WND_DRW );
  // specify the block to be inserted
  hBlock = lcDrwGetObjectByName( hDrw, LC_OBJ_BLOCK, szBlockName );
  if (hBlock != 0){
    lcPropPutHandle( 0, LC_PROP_BLKREF_BLOCK, hBlock );
    // specify position on-screen
    lcPropPutBool( 0, LC_PROP_BLKREF_ONS_XY, true );
    // set fixed scale
    lcPropPutBool( 0, LC_PROP_BLKREF_ONS_SCALE, false );
    lcPropPutFloat( 0, LC_PROP_BLKREF_SCALE, 0.5 );
    // set fixed rotation angle
    lcPropPutBool( 0, LC_PROP_BLKREF_ONS_ANGLE, false );
    lcPropPutFloat( 0, LC_PROP_BLKREF_ANGLE, 45*LC_DEG_TO_RAD );
    // run the command to insert a block without a dialog
    lcWndExeCommand( hLcWnd, LC_CMD_INSERT, LC_INSERT_NODLG );
    // get handle to the block reference that was created by the command
    hBlkRef = lcPropGetHandle( 0, LC_PROP_BLKREF_RETURN );
    if (hBlkRef != 0){
      // get coordinates of insertion point
      X = lcPropGetFloat( hBlkRef, LC_PROP_BLKREF_X );
      Y = lcPropGetFloat( hBlkRef, LC_PROP_BLKREF_Y );
    }
    // reset default mode to LC_INSERT_DLG
    lcWndExeCommand( hLcWnd, LC_CMD_INSERT, LC_INSERT_RESET );
  }
}
Used functions:

lcPropGetHandle
lcDrwGetObjectByName
lcPropPutHandle
lcPropPutBool
lcPropPutFloat
lcWndExeCommand
lcPropGetFloat