Incorrect DWG to SVG export

1
ArunaS
5/17/2019 1:44 PM

It seems when exporting input as DWG and output as SVG the image is shrinked.It is approximately 60% of the size specified.
I want the image to be size (850,530) but it turns out to be smaller.

C# Code:
          private void ExportToSvg(DxfModel model, string filename)
          {
                BoundsCalculator boundsCalculator = new BoundsCalculator();
                boundsCalculator.GetBounds(model);
                Bounds3D bounds = boundsCalculator.Bounds;

                Size size = new Size(850, 530);

                PaperSize paperSize = PaperSizes.GetPaperSize(PaperKind.A4);
                // Lengths in hundredths of cm.
                const float hundredthsInchToCm = 2.54f / 100f;
                float pageWidth = paperSize.Width * hundredthsInchToCm * 100f;
                float pageHeight = paperSize.Height * hundredthsInchToCm * 100f;
                float margin = 200f;
                // Scale and transform such that its fits max width/height
                // and the top left middle of the cad drawing will match the 
                // top middle of the svg page.
                Matrix4D to2DTransform = DxfUtil.GetScaleTransform(
                    bounds.Corner1,
                    bounds.Corner2,
                    new WW.Math.Point3D(bounds.Corner1.X, bounds.Corner2.Y, 0d),
                    new WW.Math.Point3D(0d, 530d, 0d),
                    new WW.Math.Point3D(850d, 0d, 0d),
                    new WW.Math.Point3D(0d, 0d, 0d)
                );

                using (Stream stream = File.Create(filename))
                {
                    SvgExporter exporter = new SvgExporter(stream, 850, 530);
                    exporter.Draw(model, GraphicsConfig.AcadLikeWithWhiteBackground, to2DTransform);
                }
        }

Please let me know what can be the issue in this code.
Thanks

Wout
5/17/2019 1:55 PM

You're not using the size variable.

- Wout

ArunaS
5/17/2019 2:32 PM

Thanks for the quick reply.

Modified code is this but still the same output.

private void ExportToSvg(DxfModel model, string filename)
{
BoundsCalculator boundsCalculator = new BoundsCalculator();
boundsCalculator.GetBounds(model);
Bounds3D bounds = boundsCalculator.Bounds;

System.Drawing.Size size = new System.Drawing.Size(850,530);


float margin = 200f;
// Scale and transform such that its fits max width/height
// and the top left middle of the cad drawing will match the
// top middle of the svg page.
Matrix4D to2DTransform = DxfUtil.GetScaleTransform(
bounds.Corner1,
bounds.Corner2,
new WW.Math.Point3D(bounds.Corner1.X, bounds.Corner2.Y, 0d),
new WW.Math.Point3D(0d, 530d, 0d),
new WW.Math.Point3D(850d, 0d, 0d),
new WW.Math.Point3D(0d, 0d, 0d)
);

using (Stream stream = File.Create(filename))
{
SvgExporter exporter = new SvgExporter(stream,size);
exporter.Draw(model, GraphicsConfig.AcadLikeWithWhiteBackground, to2DTransform);
}
}

The output svg should be of size(850,530)

Thanks

ArunaS
5/17/2019 6:02 PM

Hello,

Any update or solution for this?

Thanks

Wout
5/17/2019 8:22 PM

I would need the input DWG/DXF file. Also please use the code formatting tags so I don't have to edit your posts for you.

- Wout

ArunaS
5/20/2019 12:24 PM

Hi,

I am trying on the attached sample file.I have couple other sample files which I can attach if needed.

Thanks,
Aruna

Wout
5/20/2019 12:50 PM

I don't see any problem, the SVG is exactly the size you specified. The SVG header is correct, and Inkscape also shows the size you specified (see screenshot).

Code:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="850px" height="530px" viewBox="0 0 850 530" version="1.1">
  <rect x="0" y="0" width="850" height="530" fill="#FFFFFF" stroke="none" />

- Wout

ArunaS
5/20/2019 1:02 PM

Thanks for the quick reply.

Are you using the same code that I provided.And can I do something so that the drawing stretches an fits into the specified size.
In the screenshot you can see a black border.I am not sure about that.

Thanks Again,
Aruna

Wout
5/20/2019 1:16 PM

Yes ofcourse it was your code.

The rectangle is just something Inkscape shows so you see the paper size. It is the paper size you specified.

Maybe you want a portrait size? You specified a landscape size (850 width > 530 height). You should figure out your requirements.

- Wout

ArunaS
5/20/2019 1:20 PM

Thank You so much for your support.
I can speak to my team about it and get back to you if I have any other issues.

1