SetSectionBox does not update View3D

SetSectionBox does not update View3D

Anonymous
Not applicable
1,144 Views
3 Replies
Message 1 of 4

SetSectionBox does not update View3D

Anonymous
Not applicable

Hi there ! 
I'm trying to save SectionBox coordinates of the Active3DView to set it back later. But when I do it only refresh by clicking the actual SectionBox. I find this tutorial from TheBuildingCoder but I can't find any code to refresh view3D and the code is a bit outdated.

Here is my code to show you how I proceed: 
I get the SectionBox this way: 

 

BoundingBoxXYZ SectionBox = view3D.GetSectionBox();

And I set it this way:

 

BoundingBoxXYZ bbXYZ = new BoundingBoxXYZ();
bbXYZ = selected.BoundingB;
MessageBox.Show("bbmin : " + bbXYZ.Min + bbXYZ.Max); //I see here that the coordinates are Ok
if (view is View3D)
                {
                    //bbXYZ.Enabled = true; seems useless
                    //view3D.IsSectionBoxActive = true; useless as well
 
                    view3D.SetSectionBox(bbXYZ);
                }

As I said the SectionBox is set correctly but I have to click on it to refresh. Do you people know a way to refresh it automatically?
Thank you !

 

0 Likes
Accepted solutions (1)
1,145 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

Edit (can't find how to edit my post)

I find out I probably need a Transaction : 

// Set the section box back to the view (requires an open transaction)
    view3d.SetSectionBox(box);

Source : SOURCE

 

But I can't set it up this way :

using (Transaction t = new Transaction(doc, "test"))
                    {
                        t.Start();
                        view3D.SetSectionBox(bbXYZ);
                        t.Commit();

                    }

It would take me out of the Revit API context. 

Am I in the right way ? Can somebody provide me some code sample to implement a Transaction in the Revit API context inside a Click Event (WPF UI) ?

0 Likes
Message 3 of 4

Anonymous
Not applicable

After a deeper dig into the API documentation and many tests in different situations, it seems nothing about SectionBoxes is refreshing automatically. I don't know if it is an unknown issue in the 2016 release or an invisible obvious mistake but I’m stuck! 
Any hints are welcome! 

0 Likes
Message 4 of 4

Anonymous
Not applicable
Accepted solution

I find a trick to refresh the View3D! 
I find out when I’m moving the BasePoint in UI the SectionBox was updated. 
So I use this trick in API: 



view3D.SetSectionBox(bbXYZ);
                    //-*-*-*-*--*-
                    FilteredElementCollector collector = new FilteredElementCollector(doc);
                    var locations = collector.OfClass(typeof(BasePoint)).ToElements();
                    foreach (var locationPoint in locations)
                    {
                        BasePoint basePoint = locationPoint as BasePoint;
                        basePoint.Pinned = false;
                        basePoint.Location.Move(new XYZ(0, 1, 0));
                    }

                    //-*-*-*-*-*-*-*

 It may looks awful to you but it works !

0 Likes