Object Boudingbox not the same as in application

Hi all,

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.

Can anyone please help me with this problem.

Thanks in advance.

Can you post a 3dm file with the objects?

Hi,

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.

Thanks.

Hi Peter

Well … don’t know why … but I get your results
calling GetBoundingBox( false )

That is: il looks like the ‘accurate’ argument be false instead of true …

If I call GetBoundingBox( true ) on your surface, I get a range 0 … 12 ( correct ) … :confused:

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;
        }
    }


Thanks you for your replies.

i see that when i use true of false in for the accurate parameter in the boudingbox i get the same result.
i use the following:

  • Visual studio 2015
  • c#
  • installed the nuget package rhino3dnio (tried all cpu, x68 and x64)

For the test i started with a blank console app in VS2015 and used the code and also tried the code of menno with the extension method.

do i miss something or do i something wrong?

Thanks for your reply.

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.

Hello Emilio,

The 3dm files are made with Rhino 4. and the elements used are predifined in a library.
But i don’t know in what versions these are made.

rhino3dmio package

Aha! I think that when you run the code outside of rhino, the implementation reverts to the non-accurate version.

Thanks all for your help so far.
Does somebody has an idea how to measure the height of a object in a 3dm file from an external application?

Is it possible to run rhino commands from a c# application and extract the result from rhino without the 3dmio package?

Thanks

You may want to make a plugin for rhino, or use rhino COM scripting. For both you need to have the rhino application running.

@peter78, can you post one of the files you are dealing with?

– Dale

temp.3dm (172.8 KB)

@dale This file has the measurements as described.