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;
    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>();

    var dimA = dims.ToArray();

    length = dimA[2];
    width = dimA[1];
    heigth = dimA[0];
    //A = box;
  } (10.2 KB)

If anybody has an idea it will be really welcome!

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.