RP Thomas, I thank you.
This solution worked great, I translated to C# so I have posted here for C# coders.
public static void AdjustCropToSectionBox(this View3D View3D)
{
if (View3D.CropBoxActive == false)
{
View3D.CropBoxActive = true;
}
if (View3D.IsSectionBoxActive == false)
{
return;
}
BoundingBoxXYZ CropBox = View3D.CropBox;
BoundingBoxXYZ SectionBox = View3D.GetSectionBox();
Transform T = CropBox.Transform;
var Corners = BBCorners(SectionBox, T);
double MinX = Corners.Min(j => j.X);
double MinY = Corners.Min(j => j.Y);
double MinZ = Corners.Min(j => j.Z);
double MaxX = Corners.Max(j => j.X);
double MaxY = Corners.Max(j => j.Y);
double MaxZ = Corners.Max(j => j.Z);
CropBox.Min = new XYZ(MinX, MinY, MinZ);
CropBox.Max = new XYZ(MaxX, MaxY, MaxZ);
View3D.CropBox = CropBox;
}
private static XYZ[] BBCorners(BoundingBoxXYZ SectionBox, Transform T)
{
XYZ Btm_LL = SectionBox.Min; // Lower Left
var Btm_LR = new XYZ(SectionBox.Max.X, SectionBox.Min.Y, SectionBox.Min.Z); // Lower Right
var Btm_UL = new XYZ(SectionBox.Min.X, SectionBox.Max.Y, SectionBox.Min.Z); // Upper Left
var Btm_UR = new XYZ(SectionBox.Max.X, SectionBox.Max.Y, SectionBox.Min.Z); // Upper Right
XYZ Top_UR = SectionBox.Max; // Upper Right
var Top_UL = new XYZ(SectionBox.Min.X, SectionBox.Max.Y, SectionBox.Max.Z); // Upper Left
var Top_LR = new XYZ(SectionBox.Max.X, SectionBox.Min.Y, SectionBox.Max.Z); // Lower Right
var Top_LL = new XYZ(SectionBox.Min.X, SectionBox.Min.Y, SectionBox.Max.Z); // Lower Left
var Out = new XYZ[8] { Btm_LL, Btm_LR, Btm_UL, Btm_UR, Top_UR, Top_UL, Top_LR, Top_LL };
for (int i = 0, loopTo = Out.Length - 1; i <= loopTo; i++)
{
// Transform bounding box corords to model coords
Out[i] = SectionBox.Transform.OfPoint(Out[i]);
// Transform bounding box coords to view coords
Out[i] = T.Inverse.OfPoint(Out[i]);
}
return Out;
}
}