BoundingBox

Discuss and ask questions about CAD VCL (Delphi and C++ Builder).

Moderators: SDS, support, admin

Post Reply
Joe
Posts: 5
Joined: 20 Sep 2006, 17:51

BoundingBox

Post by Joe » 12 Dec 2006, 10:42

Hi,

i've the following Problem: I need the bounding-box (TFRect) from a dxf-image.

I designed an Interface, which provide me i way to access several dxf-images implemetations. In your documentation there are 4 different properties and methods to get such a boubding-box.

For Example:

* TsgDXFImage.CurrentLayout.Box
* TsgDXFImage.Extents
* TsgDXFImage.DrawingBox
* TsgDXFImage.PureExtents

I've testet all these ways to get these box, but often the results are all 0. What must be done to get the exact bouzunding-box?

~ Joe

support
Posts: 3272
Joined: 30 Mar 2005, 11:36
Contact:

Post by support » 12 Dec 2006, 11:20

Hello Joe,

<ol type="1"> <li> The following calls return the same results:

Code: Select all

<ol type="a"> <li>TsgDXFImage.CurrentLayout.Box;</li> 
<li>TsgDXFImage.IsWithoutBorder := true;
TsgDXFImage.CurrentLayout.Box;</li>
<li>TsgDXFImage.PureExtents;</li> </ol id="a">
We recommend to use <b>TsgDXFImage.CurrentLayout.Box;</b></li>
<li><blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">I've testet all these ways to get these box, but often the results are all 0. What must be done to get the exact bouzunding-box?<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
Please, give us example of your code.
</li> </ol id="1">
Sergey.


please post questions to the forum or write to support@cadsofttools.com

Joe
Posts: 5
Joined: 20 Sep 2006, 17:51

Post by Joe » 12 Dec 2006, 11:31

Hi Sergey, thanks for your quick reply.

Here an example:

Code: Select all

procedure dosomething;
var
  cad: TsgDXFImage;
  src: TFRect;

begin
  //Interface to provide dwg, dxf, ... -images
  cad := TsgDXFImage(Loader.GetImage); 
  while (cad.IsLoading and (not Assigned(cad)))do
    sleep(10);

  {BoundingBox}
  if (Assigned(cad)) then
  begin
    cad.GetExtents;
    if (Assigned(cad.CurrentLayout)) then
      src := cad.CurrentLayout.Box
    else
      src := cad.Extents;
  end;

  //do something with bounding box
end;
Sometimes <b>cad.CurrentLayout.Box</b> provide a box with (L: 1e+20, T: -1e+20, R: -1e+20, B: 1e+20) or <b>cad.Extents</b> a box with (L: 0, T: 0, R: 0, B: 0);

What is GetExtents and TsgDXFImage.Extents for?

~Joe

support
Posts: 3272
Joined: 30 Mar 2005, 11:36
Contact:

Post by support » 12 Dec 2006, 12:29

Hello Joe,

The following code works:

Code: Select all

<b>procedure</b> TForm1.Button2Click(Sender: TObject);
<b>var</b>
  cad: TsgDXFImage;
  src: TFRect;
<b>begin</b>
  //Interface to provide dwg, dxf, ... -images
  cad := TsgDXFImage.Create;
  cad.LoadFromFile(<font color="blue">'c:\Test.dxf'</font id="blue">);

  <b>while</b> (cad.IsLoading <b>and</b> (<b>not</b> Assigned(cad)))<b>do</b>
    sleep(10);

  {BoundingBox}
  <b>if</b> (Assigned(cad.CurrentLayout)) <b>then</b>
    src := cad.CurrentLayout.Box
  <b>else</b>
    src := cad.Extents;
  
  cad.Free;
<b>end</b>;
<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">What is GetExtents and TsgDXFImage.Extents for?<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
<h4>TsgDXFImage.GetExtents</h4>
<b>procedure</b> GetExtents;
<b>Description</b>
Calculates extents for all LAYOUTs and sets the model as current LAYOUT.

<h4>TsgDXFImage.Extents</h4>
<b>property</b> Extents: TFRect
<b>Description</b>
Defines drawing's extents. Returned TFRect is calculated through all entities' coordinates.

Sergey.

please post questions to the forum or write to support@cadsofttools.com

Joe
Posts: 5
Joined: 20 Sep 2006, 17:51

Post by Joe » 12 Dec 2006, 13:22

Thanks again, but it still don't work.

Why is <b>CurrentLayout</b> after loading in dxf/dwg-image (for example) nil?

What the procedure <b>RefreshCurrentLayout</b> do?

Why does after second call of <b>GetExtents</b> throw an exception?

~ Joe

support
Posts: 3272
Joined: 30 Mar 2005, 11:36
Contact:

Post by support » 12 Dec 2006, 14:05

Hello Joe,

Here goes full text of the project that we have sent you. Project contains the only button and it does work:

Code: Select all

<b>unit</b> Unit1;

<b>interface</b>

<b>uses</b>
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DXFImage, sgConsts, ExtCtrls, SGImage, StdCtrls;

<b>type</b>
  TForm1 = <b>class</b>(TForm)
    Button1: TButton;
    <b>procedure</b> Button1Click(Sender: TObject);
  <b>private</b>
    { Private declarations }
  <b>public</b>
    { Public declarations }
  <b>end</b>;

<b>var</b>
  Form1: TForm1;

<b>implementation</b>

{$R *.dfm}

<b>procedure</b> TForm1.Button1Click(Sender: TObject);
<b>var</b>
  cad: TsgDXFImage;
  src: TFRect;
<b>begin</b>
  cad := TsgDXFImage.Create;
  cad.LoadFromFile('Rect.dxf');

  <b>while</b> (cad.IsLoading <b>and</b> (<b>not</b> Assigned(cad)))<b>do</b>
    sleep(10);

    <b>if</b> (Assigned(cad.CurrentLayout)) <b>then</b>
      src := cad.CurrentLayout.Box
    <b>else</b>
      src := cad.Extents;
  cad.Free;
<b>end</b>;

<b>end</b>.
This line returns rectangle with the size 100x100:

Code: Select all

src := cad.CurrentLayout.Box
Sergey.

please post questions to the forum or write to support@cadsofttools.com

Post Reply