Rotating SectionBox is throwing box away from view crop.

Rotating SectionBox is throwing box away from view crop.

frankholidayjunior
Advocate Advocate
2,392 Views
8 Replies
Message 1 of 9

Rotating SectionBox is throwing box away from view crop.

frankholidayjunior
Advocate
Advocate

section box rotation moves the view away from the section box and view cropped area. Is there a re-centre setting or something like this that needs to be applied similar to what is in the 3d GUI?

I did try the rotate view which works really well it's just that the edge of the section box does not align with the plane of the family instances unless the rotation is from orthogonal to the cardinal axis to another rotation that is orthogonal to the cardinal axes. This would mean users still have to rotate their section box  to adjust the section box even though the view is perfectly facing forward in an isometric orientation.

 

private static void RotateBoundingBox(Document doc, View3D view3D, double frontAngle)
{
using (Transaction trans = new Transaction(doc, "Join Docs - rotate sectionbox"))
{
trans.Start();

BoundingBoxXYZ box = view3D.GetSectionBox();
if (false == box.Enabled)
{
TaskDialog.Show("Revit", "The section box for View3D isn't enabled.");
return;
}
XYZ origin = 0.5 * (box.Max - box.Min);
XYZ axis = XYZ.BasisZ;

Transform rotate = Transform.CreateRotationAtPoint(axis, frontAngle, origin);
box.Transform = box.Transform.Multiply(rotate);
view3D.SetSectionBox(box);

trans.Commit();
}
}

0 Likes
Accepted solutions (1)
2,393 Views
8 Replies
Replies (8)
Message 2 of 9

architect.bim
Collaborator
Collaborator

Hi!

I think the problem is that you use CreateRotationAtPoint method. Try CreateRotation instead. In that case the rotation point will be Origin of your section box Transform. And that is exactly what you need if you want just simply rotate view's section box.


Maxim Stepannikov | Architect, BIM Manager, Instructor
Message 3 of 9

frankholidayjunior
Advocate
Advocate

Hi Thanx I will give it a try soon.

 

0 Likes
Message 4 of 9

frankholidayjunior
Advocate
Advocate

Hi again, tried this and it had the same affect.

 

private static void RotateBoundingBox(Document doc, View3D view3D, double frontAngle)
{
using (Transaction trans = new Transaction(doc, "Join Docs - Set 3D View"))
{
trans.Start();
BoundingBoxXYZ box = view3D.GetSectionBox();
if (false == box.Enabled)
{
TaskDialog.Show("Revit", "The section box for View3D isn't enabled.");
return;
}

XYZ axis = new XYZ(0, 0, 1);
Transform rotate = Transform.CreateRotation(axis, frontAngle);
box.Transform = box.Transform.Multiply(rotate);
view3D.SetSectionBox(box);
trans.Commit();
}

}

0 Likes
Message 5 of 9

frankholidayjunior
Advocate
Advocate

perhaps my axis isn't correct, should it be some normalized value?

 

0 Likes
Message 6 of 9

architect.bim
Collaborator
Collaborator

Oh, I see. Sorry I missed the problem. If you explore the Origin point of Transform object you will see that it is not necessarily inside bounding box. And rotation is happening exactly around Origin point. That is why crop box is throwed away.


Maxim Stepannikov | Architect, BIM Manager, Instructor
0 Likes
Message 7 of 9

architect.bim
Collaborator
Collaborator

May be there is another simpler approach, but personally I managed to correctly rotate the SectionBox by complete rebuilding it using center of its bounding box as a new Origin. Take a look. I am sure it will help you to find your own solution:

210411_1617_002''.gif

 

# Python
view = doc.ActiveView
section_box = view.GetSectionBox()
length = section_box.Max.X - section_box.Min.X
width = section_box.Max.Y - section_box.Min.Y
height = section_box.Max.Z - section_box.Min.Z
transform = section_box.Transform

new_section_box = DB.BoundingBoxXYZ()
new_section_box.Min = DB.XYZ(
    -length / 2,
    -width / 2,
    -height / 2
)
new_section_box.Max = DB.XYZ(
    length / 2,
    width / 2,
    height / 2
)
new_origin = transform.OfPoint(
    (section_box.Min + section_box.Max) / 2
)
transform.Origin = new_origin
new_transform = transform.Multiply(
    DB.Transform.CreateRotation(
        DB.XYZ.BasisZ,
        DB.UnitUtils.ConvertToInternalUnits(
            15,
            DB.DisplayUnitType.DUT_DECIMAL_DEGREES
        )
    )
)
new_section_box.Transform = new_transform

with DB.Transaction(doc, 'Rotate Section Box') as t:
    t.Start()
    view.SetSectionBox(new_section_box)
    t.Commit()

 

 


Maxim Stepannikov | Architect, BIM Manager, Instructor
0 Likes
Message 8 of 9

architect.bim
Collaborator
Collaborator
Accepted solution

Another solution. You can get section box element and rotate it:

view = doc.ActiveView
section_box = view.GetSectionBox()
section_box_center = section_box.Transform.OfPoint(
    (section_box.Min + section_box.Max) / 2
)
section_box_element_id = DB.ElementId(view.Id.IntegerValue - 1)

with DB.Transaction(doc, 'Rotate Section Box') as t:
    t.Start()
    DB.ElementTransformUtils.RotateElement(
        doc,
        section_box_element_id,
        DB.Line.CreateUnbound(
            section_box_center,
            DB.XYZ.BasisZ
        ),
        DB.UnitUtils.ConvertToInternalUnits(
            15,
            DB.DisplayUnitType.DUT_DECIMAL_DEGREES
        )
    )
    t.Commit()

The relation between view Id and its section box element Id was found in this post. 


Maxim Stepannikov | Architect, BIM Manager, Instructor
Message 9 of 9

frankholidayjunior
Advocate
Advocate

//here is the c# version, thanx a lot may you dance with friendly bears tonight!

also I visited your website and although most was in russian language, it looked polished

 

internal static void RotateSectionBox(Document doc, View3D view3D, double frontAngle)
{
BoundingBoxXYZ section_box = view3D.GetSectionBox();
XYZ section_box_center = section_box.Transform.OfPoint((section_box.Min + section_box.Max) / 2);
ElementId section_box_element_id = new ElementId(view3D.Id.IntegerValue - 1);
{
Line line = Line.CreateUnbound(section_box_center, XYZ.BasisZ);

using (Transaction trans = new Transaction(doc, "rotate"))
{
trans.Start();
ElementTransformUtils.RotateElement(doc,
section_box_element_id,
line,
frontAngle
//UnitUtils.ConvertToInternalUnits(15, DisplayUnitType.DUT_DECIMAL_DEGREES)
);
trans.Commit();
}
}
}