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
{
RhinoDoc.ActiveDoc.Objects.UnselectAll();
List crvs = new List();
var geometry = new List();
using (var CurveDocument = RhinoDoc.CreateHeadless(null))
{
CurveDocument.Import(file);
foreach (var obj in CurveDocument.Objects)
{
if (obj.ObjectType == ObjectType.Curve)
{
CurveObject crv_obj = obj as CurveObject;
Curve crv = crv_obj.CurveGeometry.DuplicateCurve();
crvs.Add(crv);
}
}
}
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
ALSO
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.
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
@chris.botha what @11159 is trying to say your code should be something like:
bb = Rhino.Geometry.BoundingBox.Unset
for crv in crvs:
bb.Union(crv.GetBoundingBox(True))
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.
(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.