Box dimensions C#

Hi all,

what would be the easiest to get the dimensions of a box that is not aligned to the World XY plane?

I am doing it like this for the moment, but it I think there might be something way easier I am missing.

 private void RunScript(Brep x, ref object length, ref object width, ref object heigth, ref object A)
  {
    double[] area = new double[6];
    var indices = new List<int>();
    for (int i = 0; i < 6; i++)
    {
      x.Faces[i].SetDomain(0, new Interval(0, 1));
      x.Faces[i].SetDomain(1, new Interval(0, 1));
      double dis = x.Faces[i].PointAt(0, 0).DistanceTo(x.Faces[i].PointAt(1, 1));
      area[i] = dis;
      indices.Add(i);
    }
    var indArray = indices.ToArray();
    Array.Sort(area, indArray);

    Plane plane;
    bool frame = x.Faces[indArray[0]].FrameAt(0.5, 0.5, out plane);
    Box box = new Box(plane, x);

    var dims = new List<double>();
    dims.Add(box.GetCorners()[0].DistanceTo(box.GetCorners()[1]));
    dims.Add(box.GetCorners()[1].DistanceTo(box.GetCorners()[2]));
    dims.Add(box.GetCorners()[1].DistanceTo(box.GetCorners()[5]));

    var dimA = dims.ToArray();
    Array.Sort(dimA);

    length = dimA[2];
    width = dimA[1];
    heigth = dimA[0];
    //A = box;
  }

File:201090417_BoxProperties.gh (10.2 KB)

If anybody has an idea it will be really welcome!
Thanks!

Hi @Baris,

If the Brep is really a box, then all of the faces will be planar. Thus, you can get one of the face’s plane - BrepFace.TryGetPlane - and use that plane as input to Brep.GetBoundingBox.

– Dale

1 Like

HI @dale,

thanks for the prompt answer!

That`s way easier.