I have a 3dm file with several objects i would like to determine the highest object in this file. I do this by looping all objects and setting a boundingbox around it. But when i look at the Z coordinates the height is not the same as when i measure it in Rhino.
I Use the following code i simplified it so it is not so long:
// Get the model
var model = File3dm.Read(filename);
// For this examplei use object 3 and get the boudingbox from it.
var corners = model.Objects[3].Geometry.GetBoundingBox(true).GetCorners();
When i check the Z coordinates from the result the height is (13.82 - -0.15) 13.97
But when i put a boundingbox around this object in Rhino i get the height of 12mm.
This is the file i use for testing. temp.3dm (172.8 KB)
i searched some more and find that the corner coordinates should be transformed from plane to world?
I’m complete new to this and did not figured out how to do this. Can you please help.
Weird. If I run the code below I get the same answer in both cases.
{
ObjRef[] bRefs;
Result res = RhinoGet.GetMultipleObjects("Sel obj", false, ObjectType.Brep, out bRefs);
if (res != Result.Success || null == bRefs) return res;
Brep[] breps = bRefs.Select(r => r.Brep()).ToArray();
BoundingBox bb = breps.GetBoundingBox(true);
RhinoApp.WriteLine("Rhino Height: {0}", bb.Max.Z - bb.Min.Z);
bb = BoundingBox.Unset;
var f = File3dm.Read(@"C:\Users\mdeij\Downloads\temp.3dm");
bb = f.Objects.Select(o => o.Geometry).GetBoundingBox(true);
RhinoApp.WriteLine("File Height: {0}", bb.Max.Z - bb.Min.Z);
}
Note, this uses the following extension method
public static class Ext
{
/// <summary>
/// Compute the union of bounding boxes of all geometries in the collection.
/// Any null entries are skipped. An empty or null collection will return <see cref="BoundingBox.Unset"/>
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="geometries"></param>
/// <param name="accurate"></param>
/// <returns></returns>
public static BoundingBox GetBoundingBox<T>(this IEnumerable<T> geometries, bool accurate)
where T : GeometryBase
{
if (null == geometries)
return BoundingBox.Unset;
BoundingBox bb = BoundingBox.Unset;
foreach (T b in geometries)
{
if (null == b)
continue;
bb.Union(b.GetBoundingBox(accurate));
}
return bb;
}
}
BTW, Peter, are you using the latest Rhino version or an older one ?
I think I remember a problem in the bounding box calculation quite some time ago …
But I’m not sure, sorry.