BoundingBox broken for SVG but not other formats

Morning All,

Our application requires us to manipulate curves (transform/scale) after importing from ERP.
Using this code we are able to bring in our DXF and SVG Curves.

string file = InputsFromRhino[box].MeshFile.ToLower();
if (file.Contains(“dxf”) || file.Contains(“svg”)) //we found a laser job
List crvs = new List();
var geometry = new List();

using (var CurveDocument = RhinoDoc.CreateHeadless(null))
    foreach (var obj in CurveDocument.Objects)
        if (obj.ObjectType == ObjectType.Curve)
            CurveObject crv_obj = obj as CurveObject;
            Curve crv = crv_obj.CurveGeometry.DuplicateCurve();

and in the case of the result from DXF file this code is able to determine the correct size (bounding box) of the DXF (20.63mm)

And when adding the curves from these files to Rhino directly both SVG and DXF the file is imported at correct size (20.63)

However I need to scale the file to a user selected size passed to us from our website, so I get boundingboxes and determine Source X and Target X and scale accordingly.

For DXF this is flawless… for SVG the boundingbox is wildly innacurate.



so again, this works flawlessly for DXF, but is way off the mark on the svg curves


If I manually import the file in rhino, and run boundingbox on the command line on it, the size IS correct so only in this code version is it broken.

image (2.6 KB)
adding the test files

i just noted Min.X for SVG is Zero, which is wrong, its meant to be 2.552

Hi @chris.botha,

This seems to work with your two files.

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
  string fileName = null;
  var rc = RhinoGet.GetString("Name of file to import", false, ref fileName);
  if (rc != Result.Success)
    return rc;

  fileName = fileName.Trim();
  if (string.IsNullOrEmpty(fileName))
    return Result.Nothing;

  if (!File.Exists(fileName))
    return Result.Nothing;

  using (var importDoc = RhinoDoc.CreateHeadless(null))
    importDoc.ModelUnitSystem = doc.ModelUnitSystem;
    foreach (var obj in importDoc.Objects)
      if (obj.ObjectType == ObjectType.Curve)
        var crv_obj = obj as CurveObject;
        var crv = crv_obj.CurveGeometry.DuplicateCurve();


  return Result.Success;

Keep in mind that AutoCAD files are unitless, and SVG are (probably) in pixels).

– Dale

Hi Dale,

Added the model units, but MinX is still zero, where its meant to be 2.552

Both dxf and svg import perfectly on size, using this routine (even its previous incantation)
My issue is i need to scale it from-to, and the from needs to be determined from the union bounding box, which it seesm in the case of SVG always starts at zero…

I am testing using a file located even further from Zero to bugshoot

Ok so no matter where or how i place the SVG its bounding box MinX MinY is always Zero.

Any Clues here @dale


BoundingBox is a value type because it is a Struct, not a Class.
When you create it in the constructor, you get 0 for X and Y.

BoundingBox bbox = new BoundingBox();

BoundingBox bbox = BoundingBox.Unset;

How about then?


@chris.botha what @11159 is trying to say your code should be something like:

bb = Rhino.Geometry.BoundingBox.Unset
for crv in crvs:

That will give you the expected answer.

Since newing up a bounding box gives you one with minimum and maximum at 0 that gets unioned in as well. That is why you get 0 where you were expecting 2.552.


@masaki20000915 @nathanletwory

That did the trick thanks! So strange it was not an issue with DXF import on the SVG ones?

Im able to move my project forward many thanks!

(NM… figured it out, the dxfs come in properly centred over origin so the bounding box include negative X and Y coords meaning the box is correct, the SVG come is bottom left quadrants for some odd reason so never go under Zero.

1 Like