Skip to main content

How to read a specific file format with CAD VCL?

CAD VCL provides CAD reading and visualization. Use a corresponding class to read file formats from the table below.

Classes and the file formats they support​

ClassFile format
TsgHPGLImagePLT, HGL, HG, HPG, PLO, HP, HP1, HP2, HP3, HPGL, HPGL2, HPP, GL, GL2, PRN, SPL, RTL, PCL
TsgSVGImageSVG, SVGZ
TsgDXFImageDXF
TsgCADDXFImageDXF
TsgDWFImageDWF
TsgDWGImageDWG
TsgCGMImageCGM

If you need to read the DWF format, use TsgDWFImage; to read SVG, use TsgSVGImage etc.

For example, let's read DXF files. The corresponding class for reading DXF is TsgDXFImage.

  1. Add DXF to the uses section. Create a new procedure to read DXF.
uses DXF;
...
type

TForm1 = class(TForm)
FImage: TImage;
...
implementation
...
procedure TForm1.ReadDXFClick(Sender: TObject);
  1. Declare the local variable vDrawing. Specify TsgDXFImage as its type.
var
vDrawing: TsgDXFImage;
  1. Create an instance of the TsgDXFImage object, and then call the LoadFromFile method of this class. Remember to use the try...finally construct to avoid memory leaks.
begin
vDrawing := TsgDXFImage.Create;
try
vDrawing.LoadFromFile('Entities.dxf');
FImage.Canvas.StretchDraw(Rect(0, 0,
Round(vDrawing.Width * FImage.Height / vDrawing.Height), FImage.Height), vDrawing);
finally
vDrawing.Free;
end;

You have written the procedure to read DXF files.

The full code listing.

uses DXF;
...
type

TForm1 = class(TForm)
FImage: TImage;
...
implementation
procedure TForm1.ReadDXFClick(ASender: TObject);
var
vDrawing: TsgDXFImage;
begin
vDrawing := TsgDXFImage.Create;
try
vDrawing.LoadFromFile('Entities.dxf');
FImage.Canvas.StretchDraw(Rect(0, 0,
Round(vDrawing.Width * FImage.Height / vDrawing.Height), FImage.Height), vDrawing);
finally
vDrawing.Free;
end;
end;
Note

Zooming and panning of the drawing are implemented in the Viewer demo via the special TsgDrawingNavigator viewer control.