void DemoLoadBlocks (HANDLE hLcWnd)
{
HANDLE hBlock, hLcDrw;
HANDLE hExtDrw, hBlock2, hEnt;
BOOL bLoaded;
HWND hWnd;
int i;
double x, y, dx, Xmin, Ymin, Xmax, Ymax, W, Scale, Xins, Yins, Xbp, Ybp;
WCHAR* szFileName = L"c:/!OK/Data/Drawings/Legends.dxf";
WCHAR* szBlockName[5];
// get a drawing and a block linked with Litecad window (m_hLcWnd)
hBlock = lcPropGetHandle( hLcWnd, LC_PROP_WND_BLOCK );
hLcDrw = lcPropGetHandle( hLcWnd, LC_PROP_WND_DRW );
// create object for external drawing
hExtDrw = lcCreateDrawing();
// load a file into external drawing
bLoaded = lcDrwLoad( hExtDrw, szFileName, NULL );
if (bLoaded){
// get names of blocks which exist in the external drawing
szBlockName[0] = L"41";
szBlockName[1] = L"CHIKKU";
szBlockName[2] = L"COC1";
szBlockName[3] = L"KM";
szBlockName[4] = L"TP";
x = 0.0;
y = 0.0;
dx = 10.0;
hWnd = (HWND)lcPropGetHandle( hLcWnd, LC_PROP_WND_HWND );
for (i=0; i<5; ++i){
// add new block from external drawing (hExtDrw) into current drawing (hLcDrw)
hBlock2 = lcDrwAddBlockFromDrw( hLcDrw, szBlockName[i], hExtDrw, LC_BLOCK_OVERWRITEYES, hWnd );
if (hBlock2){
// get block basepoint
Xbp = lcPropGetFloat( hBlock2, LC_PROP_BLOCK_X );
Ybp = lcPropGetFloat( hBlock2, LC_PROP_BLOCK_Y );
// get block extents
Xmin = lcPropGetFloat( hBlock2, LC_PROP_BLOCK_XMIN );
Ymin = lcPropGetFloat( hBlock2, LC_PROP_BLOCK_YMIN );
Xmax = lcPropGetFloat( hBlock2, LC_PROP_BLOCK_XMAX );
Ymax = lcPropGetFloat( hBlock2, LC_PROP_BLOCK_YMAX );
W = Xmax - Xmin; // block width
// calc scale for block ref., in order to fit to cell width (dx)
Scale = dx / W;
// calc coordinates of insertion point, in order block ref. adjust to x,y by left-bottom corner
Xins = x + (Xbp - Xmin)*Scale;
Yins = y + (Ybp - Ymin)*Scale;
// add block reference
hEnt = lcBlockAddBlockRef( hBlock, hBlock2, Xins, Yins, Scale, 0.0 );
x = x + dx;
}
}
lcDeleteDrawing( hExtDrw );
// display rects of entities extents
lcPropPutBool( 0, LC_PROP_G_ENTEXT, true );
// zoom extents
lcWndZoomRect( hLcWnd, 0.0, 0.0, 0.0, 0.0 );
}
}