blank dxf file

If you have any comments or questions about our developing tools, please do not hesitate to contact us at this forum

Moderators: admin, SDS, support

blank dxf file

Postby slbarker » 27 Oct 2006, 14:18

Hi Sergey.

I've made some progress from my last problem. I found I had to export to a temporary dxf file, then import it back in. Is there a better way?

I have the following 2 issues now:

1. The blank dxf isn't actually blank, so I'd like to get rid of the rectangle without losing the aspect ratio (which matches the original bitmap selected by the user).
2. In order to export a dxf I needed to download
http://www.cadsofttools.com/download/dxfexportvcl.zip
which now has the demo messagebox when accessed. Does my purchase of cadimportvcl (with source) qualify for registration of this export component as well?

thanks,
Steve

current code snippet:
Code: Select all
...
    if ext = '.bmp' then begin
      BMOverlay.LoadFromFile(sFileName);  // bitmap overlay

      // create a dummy blank dxf image so we have something to draw on and create measurements
      vImg := TsgDXFImage.Create;
      try
        vImg.IsWithoutBorder := True;
        // draw a rectangle the same size as the bitmap overlay to get the aspect ration correct
        vLine1 := TsgDXFLine.Create;
        vLine1.Point := MakeFPoint(0,0,0);
        vLine1.Point1 := MakeFPoint(0,BMOverlay.Height,0);
        vImg.Converter.Sections[csEntities].AddEntity(vLine1);
        vLine2 := TsgDXFLine.Create;
        vLine2.Point := MakeFPoint(0,BMOverlay.Height,0);
        vLine2.Point1 := MakeFPoint(BMOverlay.Width,BMOverlay.Height,0);
        vImg.Converter.Sections[csEntities].AddEntity(vLine2);
        vLine3 := TsgDXFLine.Create;
        vLine3.Point := MakeFPoint(BMOverlay.Width,BMOverlay.Height,0);
        vLine3.Point1 := MakeFPoint(BMOverlay.Width,0,0);
        vImg.Converter.Sections[csEntities].AddEntity(vLine3);
        vLine4 := TsgDXFLine.Create;
        vLine4.Point := MakeFPoint(BMOverlay.Width,0,0);
        vLine4.Point1 := MakeFPoint(0,0,0);
        vImg.Converter.Sections[csEntities].AddEntity(vLine4);
        if Assigned(vImg.Converter.OnCreate) then begin
          vImg.Converter.OnCreate(vLine1);
          vImg.Converter.OnCreate(vLine2);
          vImg.Converter.OnCreate(vLine3);
          vImg.Converter.OnCreate(vLine4);
        end;
        vImg.Converter.Loads(vLine1);
        vImg.Converter.Loads(vLine2);
        vImg.Converter.Loads(vLine3);
        vImg.Converter.Loads(vLine4);
        vImg.CurrentLayout := vImg.Layouts[0];
        vImg.DrawingBox := MakeFRect(0,BMOverlay.Height,0, BMOverlay.Width,0,0);
        vImg.GetExtents;
        // export to a temporary dxf file
        tempFile := ExtractFilePath(Application.ExeName)+'temp.dxf';
        E := TsgDXFExport.Create;
        try
          E.IsParseWhite := True;
          vMet := vImg.ExportToMetafile(vOffX, vOffY, vUSize);
          DXFExport.OffsetX := vOffX;
          DXFExport.OffsetY := vOffY;
          E.UnitSize := vUSize;
          E.LoadFromMetafile(vMet);
          vMet.Free;
          E.SaveToFile(tempFile);
        finally
          E.Free;
        end;
        // read it back in. sgPaintBox.OnPaint overlays the bitmap
        // I would like to get rid of the visible rectangle somehow
        sgPaintBox.LoadFromFile(tempFile);  // dummy frame
        IsBitMap := true;
      finally
        vImg.Free;
      end;
    end else begin
      // standard dxf or dwg files - no bitmap overlay required
      sgPaintBox.LoadFromFile(sFileName);
      IsBitMap := false;
    end;
    Img := TsgDXFImage(sgPaintBox.Picture.Graphic);
...
slbarker
 
Posts: 10
Joined: 03 Nov 2005, 21:39
Location: New Zealand

Postby slbarker » 01 Nov 2006, 00:02

Mostly sorted now,

Steve
slbarker
 
Posts: 10
Joined: 03 Nov 2005, 21:39
Location: New Zealand

Postby support » 01 Nov 2006, 13:00

Hi Steve,

1. Please try the code below.
2. Please contact us on info@cadsofttools.com on this question.
Code: Select all
<b>uses</b>
  ... SGImage, DXFImage, DXFConv, DXFExport, sgConsts;

<b>type</b>
  TForm1 = <b>class</b>(TForm)
    ...
    sgPaintBox: TsgImage;
    <b>procedure</b> Button1Click(Sender: TObject);
  <b>private</b>
    <i><font color="blue">{ Private declarations }</font id="blue"></i>
    FImg: TsgDXFImage;

...

<b>procedure</b> TForm1.Button1Click(Sender: TObject);
<b>var</b>
  vPoly: TsgDXFPolyLine;
  BMOverlay: TBitmap;
  E: TsgDXFExport;
  vMet: TMetafile;
  vOffX, vOffY, vUSize: TsgFloat;
  Vertex: TsgDXFVertex;
<b>begin</b>
  BMOverlay := TBitmap.Create;
  BMOverlay.LoadFromFile(<font color="blue">'c:\Rect.bmp'</font id="blue">);  <font color="blue">// bitmap overlay
    // create a dummy blank dxf image so we have something to draw on and create measurements</font id="blue">
  FImg := TsgDXFImage.Create;
  <b>try</b>
    FImg.CurrentLayout := FImg.Layouts[<font color="blue">0</font id="blue">];
   
    vPoly := TsgDXFPolyLine.Create;
    FImg.Converter.Sections[csEntities].AddEntity(vPoly);
    vPoly.Closed := True;

    Vertex := TsgDXFVertex.Create;
    Vertex.Point := MakeFPoint(<font color="blue">0</font id="blue">,<font color="blue">0</font id="blue">,<font color="blue">0</font id="blue">);
    vPoly.AddEntity(Vertex);

    Vertex := TsgDXFVertex.Create;
    Vertex.Point := MakeFPoint(<font color="blue">0</font id="blue">,BMOverlay.Height,<font color="blue">0</font id="blue">);
    vPoly.AddEntity(Vertex);

    Vertex := TsgDXFVertex.Create;
    Vertex.Point := MakeFPoint(BMOverlay.Width,BMOverlay.Height,<font color="blue">0</font id="blue">);
    vPoly.AddEntity(Vertex);

    Vertex := TsgDXFVertex.Create;
    Vertex.Point := MakeFPoint(BMOverlay.Width,<font color="blue">0</font id="blue">,<font color="blue">0</font id="blue">);
    vPoly.AddEntity(Vertex);

    FImg.Converter.Loads(vPoly);
    <b>if</b> Assigned(FImg.Converter.OnCreate) <b>then
    begin</b>
      FImg.Converter.OnCreate(vPoly);
    <b>end</b>;

    FImg.DrawingBox := MakeFRect(<font color="blue">0</font id="blue">,BMOverlay.Height,<font color="blue">0</font id="blue">, BMOverlay.Width,<font color="blue">0</font id="blue">,<font color="blue">0</font id="blue">);
    <font color="blue">// <i>export to a temporary dxf file</font id="blue"></i>
    E := TsgDXFExport.Create;
    <b>try</b>
      E.IsParseWhite := True;
      vMet := FImg.ExportToMetafile(vOffX, vOffY, vUSize);
      DXFExport.OffsetX := vOffX;
      DXFExport.OffsetY := vOffY;
      E.UnitSize := vUSize;
      E.LoadFromMetafile(vMet);
      vMet.Free;
      E.SaveToFile(<font color="blue">'c:\Rect.dxf'</font id="blue">);
    <b>finally</b>
      E.Free;
    <b>end</b>;
  <b>finally</b>
    FImg.Free;
    BMOverlay.Free;
  <b>end</b>;
  sgPaintBox.LoadFromFile(<font color="blue">'c:\Rect.dxf'</font id="blue">);  <font color="blue">// <i>dummy frame</i></font id="blue">
  sgPaintBox.Align := alClient;
  TsgDXFImage(sgPaintBox.Picture.Graphic).IsWithoutBorder := True;
<b>end</b>;

<b>Note</b>: the following line:
Code: Select all
  FImg.GetExtents;

is not necessary after this one:
Code: Select all
  FImg.DrawingBox := MakeFRect(<font color="blue">0</font id="blue">,BMOverlay.Height,<font color="blue">0</font id="blue">, BMOverlay.Width,<font color="blue">0</font id="blue">,<font color="blue">0</font id="blue">);

Sergey.



please post questions to the forum or write to support@cadsofttools.com
support
 
Posts: 2226
Joined: 30 Mar 2005, 08:36
Location: Russia


Return to CADImportVCL + DXFExportVCL

Who is online

Users browsing this forum: Exabot [Bot] and 2 guests

cron