uses CADImage, DXFConv, sgConsts, sgFunction;
...
type
TForm1 = class(TForm)
Image1: TImage;
...
implementation
procedure TForm1.AddEntitiesClick(Sender: TObject);
var
vDrawing: TsgCADImage;
vLayer: TsgDXFLayer;
vCircle: TsgDXFCircle;
vLine: TsgDXFLine;
vPoly: TsgDXFLWPolyline;
vVertex: TsgDXFVertex;
vText: TsgDXFText;
begin
// creating a new drawing structure
vDrawing := TsgCADImage.Create();
vDrawing.Converter.InitializeSections();
vDrawing.CurrentLayout := vDrawing.Layouts[0];
// creating a new layer
vLayer := TsgDXFLayer.Create;
vLayer.Name := 'Line';
vLayer.Color := $7F9FFF;
vLayer.LineWeight := 2;
// adding the new layer to the drawing
vDrawing.Converter.Loads(vLayer);
vDrawing.Converter.Sections[csLayers].AddEntity(vLayer);
// creating a new circle entity
vCircle := TsgDXFCircle.Create();
vCircle.Color := clRed;
vCircle.Point := MakeFPoint(100, 100, 0);
vCircle.Radius := 50;
// adding a new entity to the drawing
vDrawing.Converter.Loads(vCircle);
vDrawing.CurrentLayout.AddEntity(vCircle);
// creating a line
vLine := TsgDXFLine.Create;
vLine.Point := MakeFPoint(0, 0, 0);
vLine.Point := MakeFPoint(100, 100, 0);
vLine.Layer := vLayer; // the line takes the color and lineweight of the layer
vDrawing.Converter.Loads(vLine);
vDrawing.CurrentLayout.AddEntity(vLine);
// creating a 2d polyline
vPoly := TsgDXFLWPolyline.Create;
vPoly.Closed := True;
vVertex := TsgDXFVertex.Create; // vertexes are points of a polyline
vVertex.Point := MakeFPoint(0, 300, 0);
vPoly.AddEntity(vVertex);
vVertex := TsgDXFVertex.Create;
vVertex.Point := MakeFPoint(250, 300, 0);
vVertex.Bulge := 0.5; //an arc segment
vPoly.AddEntity(vVertex);
vVertex := TsgDXFVertex.Create;
vVertex.Point := MakeFPoint(250, 0, 0);
vPoly.AddEntity(vVertex);
vPoly.ColorCAD := MakeColorCAD(acIndexColor,5); // AutoCAD index color
vDrawing.Converter.Loads(vPoly);
vDrawing.CurrentLayout.AddEntity(vPoly);
// creating a text
vText := TsgDXFText.Create;
vText.Text := 'CAD Import VCL examples';
vText.Point := MakeFPoint(10, 280, 0);
vText.Height := 10;
vText.Color := clTeal;
vDrawing.Converter.Loads(vText);
vDrawing.CurrentLayout.AddEntity(vText);
// recalculation of drawing extents
vDrawing.GetExtents();
//------------------
Image1.Canvas.StretchDraw(Rect(0, 0,
Round(vDrawing.Width * Image1.Height / vDrawing.Height), Image1.Height), vDrawing);
vDrawing.Free;
// See AddEntities demo to find examples of adding other entities and structures
end;
Go to CAD VCL Enterprise