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
DXF
to theuses
section. 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
. SpecifyTsgDXFImage
as its type.
var
vDrawing: TsgDXFImage;
- Create an instance of the
TsgDXFImage
object, and then call theLoadFromFile
method of this class. Remember to use thetry...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;
Zooming and panning of the drawing are implemented in the Viewer demo via the special TsgDrawingNavigator
viewer control.