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​
| Class | File format |
|---|---|
| TsgHPGLImage | PLT, HGL, HG, HPG, PLO, HP, HP1, HP2, HP3, HPGL, HPGL2, HPP, GL, GL2, PRN, SPL, RTL, PCL |
| TsgSVGImage | SVG, SVGZ |
| TsgDXFImage | DXF |
| TsgCADDXFImage | DXF |
| TsgDWFImage | DWF |
| TsgDWGImage | DWG |
| TsgCGMImage | CGM |
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.
- Add
DXFto theusessection. Create a new procedure to read DXF.
uses DXF;
...
type
TForm1 = class(TForm)
FImage: TImage;
...
implementation
...
procedure TForm1.ReadDXFClick(Sender: TObject);
- Declare the local variable
vDrawing. SpecifyTsgDXFImageas its type.
var
vDrawing: TsgDXFImage;
- Create an instance of the
TsgDXFImageobject, and then call theLoadFromFilemethod of this class. Remember to use thetry...finallyconstruct 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;
Zooming and panning of the drawing are implemented in the Viewer demo via the special TsgDrawingNavigator viewer control.