Skip to main content

Load the CAD file procedure

uses DWG, DXF, CGM, HPGL2, SVG;

...

type

TForm1 = class(TForm)

Image1: TImage;

...

implementation

procedure TForm1.LoadFileClick(Sender: TObject);
var
// Delphi TPicture object works with CAD files when
// CAD Import VCL libraries are in uses section
vPicture: TPicture;
// for calculation of drawing visualization rectangle
vRect: TRect;
vRatioW, vRatioH: double;
begin
vPicture := TPicture.Create;
if OpenPictureDialog1.Execute then
vPicture.LoadFromFile(OpenPictureDialog1.FileName);
//calculating the drawing visualization rectangle
// vPicture.Graphic stores CAD graphic if you open DWG, DXF, PLT or
// other supported CAD extension
vRect := Image1.ClientRect;
vRatioW := vRect.Right/vPicture.Graphic.Width;
vRatioH := vRect.Bottom/vPicture.Graphic.Height;
if (vRatioW > vRatioH) then
vRect.Right := Round(vPicture.Graphic.Width * vRatioH)
else
vRect.Bottom := round(vPicture.Graphic.Height * vRatioW);
Image1.Canvas.StretchDraw(vRect, vPicture.Graphic);
end;