How to modify the far clip offset of a view section?

How to modify the far clip offset of a view section?

Anonymous
Not applicable
5,091 Views
7 Replies
Message 1 of 8

How to modify the far clip offset of a view section?

Anonymous
Not applicable

Hi, everyone.

 

The Revit API is still new to me. I'm in the process of making a Revit addin that creates a view section cut and sets its far clip offset to 1/16" by default. In searching through the API, I wasn't able to find a property or method that would allow me to directly modify the far clip offset. I know, from the remarks of the ViewSection.CreateSection Method, that "the far clip distance will be equal to the difference of the z-coordinates of BoundingBoxXYZ.Min and BoundingBoxXYZ.Max," and, from the BuiltInParameter Enumeration, that VIEWER_BOUND_OFFSET_FAR can be used to access the far clip offset (I think it's read-only?).

I'm wondering if anyone knows of a workaround for modifying the far clip offset of a view section, as I'm still surprised that I don't see a property for it. Would I have to modify the coordinates of the BoundingBoxXYZ?

 

I apologize in advance if there is an obvious solution; I've been genuinely unsuccessful in finding one.

 

Any advice is much appreciated.

0 Likes
Accepted solutions (1)
5,092 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable

I bet you are trying to do what everyone wants, which is to avoid the huge number of man-hours wasted every day by the section box far clip flying out to never-never-land where it is painfully awkward to find and less painfully corrected by interrupting the workflow focus with a trip trying to navigate through the properties box. We all have workarounds like keeping sections sitting around to be moved just to avoid the far clip issue. It is good idea. I'm thinking one variant for a tool is a quick two click operation. Pick the command, pick the section.

 

I think your answer is to modify the BoundingBoxXYZ. I don't know for sure but I do know that fooling with the BoundingBoxXYZ for a section box in a 3d view is what it takes to move and change its shape. I experimented with using keystrokes to move a section box's faces in an attempt to get around the other huge time waster, trying to grab one of those manipulation arrows. The experiment worked but the regen delay made it not very interesting. I don't have the code handy, but I do recall in the reading up for it that a 2d section is controlled the same way. Good luck. I am going to give this idea a shot also.

0 Likes
Message 3 of 8

Anonymous
Not applicable
Accepted solution

Sorry, I was wrong. The far clip is a parameter. The following changes the far clipping to 4 feet for the view object thisV.

 

 using (Transaction t = new Transaction(thisDoc, "FarSide Change")) {
                    t.Start();
                    Parameter vFarclip = thisV.get_Parameter(BuiltInParameter.VIEWER_BOUND_OFFSET_FAR);
                    vFarclip.SetValueString("4");
                    t.Commit();
                }

This command class show the same but at 1/16".

 

 

[Transaction(TransactionMode.Manual)]
    public class SectionFarClip : IExternalCommand {
        public Result Execute(
          ExternalCommandData commandData,
          ref string message,
          ElementSet elements) {
            try {
                UIApplication uiapp = commandData.Application;
                UIDocument uidoc = uiapp.ActiveUIDocument;
                Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
                Document thisDoc = uidoc.Document;

                Selection sel = uidoc.Selection;
                Section2dPickFilter selFilter = new Section2dPickFilter(thisDoc);

                Reference pickedRef = sel.PickObject(ObjectType.Element, selFilter, "Select a section to far clip adjust");
                Element elem = thisDoc.GetElement(pickedRef);

                // sheesh, another crazy linq way to do this
                FilteredElementCollector viewCollector = new FilteredElementCollector(thisDoc);
                viewCollector.OfClass(typeof(Autodesk.Revit.DB.View));
                Func<Autodesk.Revit.DB.View, bool> isNamedView = v2 => (v2.Name.Equals(elem.Name));
                Autodesk.Revit.DB.View thisV = viewCollector.Cast<Autodesk.Revit.DB.View>().First<Autodesk.Revit.DB.View>(isNamedView);

                using (Transaction t = new Transaction(thisDoc, "FarSide Change")) {
                    t.Start();
                    Parameter vFarclip = thisV.get_Parameter(BuiltInParameter.VIEWER_BOUND_OFFSET_FAR);
                    vFarclip.SetValueString("0.00529833");
                    t.Commit();
                }

            } catch (Exception ex) {
                MessageBox.Show(ex.Message, "Sorry, No Can Do.");
            }
            return Result.Succeeded;
        }
    }
Message 4 of 8

Anonymous
Not applicable

Thank you very much, aksaks! I've never known how to modify the built-in parameters as you did, here; this will be good to know in the future.

If I may ask, which namespace is the Section2dPickFilter derived from? Did you make it yourself?

 

Thanks again!

 

0 Likes
Message 5 of 8

Anonymous
Not applicable

When I started working through the problem of having mile deep sections, I used the dynamic model updater tutorial detailed on The Building Coder blog here: http://thebuildingcoder.typepad.com/blog/2012/06/documentchanged-versus-dynamic-model-updater.html 

 

Pretty much just change references from elevation to section and away you go. As aksaks pointed out, updating the depth is pretty slick:

 

Parameter fc = view.get_Parameter(BuiltInParameter.VIEWER_BOUND_OFFSET_FAR);
                fc.Set(5);

Now whenever someone draws a section the depth is set to 5'. 

 

 

 

 

0 Likes
Message 6 of 8

Anonymous
Not applicable

Section2dPickFilter? Darn, I accidentally omitted that. Sorry, I intended to provide all the parts. Here it is. 

 

 public class Section2dPickFilter : ISelectionFilter {
        Document doc = null;
        public Section2dPickFilter(Document document) {
            doc = document;
        }
        public bool AllowElement(Element e) {
            if ((BuiltInCategory)e.Category.Id.IntegerValue ==
                BuiltInCategory.OST_Viewers) {
                return true;
            }
            return false;
        }
        public bool AllowReference(Reference r, XYZ p) {
            return false;
        }
    }

 

 

Message 7 of 8

Anonymous
Not applicable

I'm a bit worried about using the documentchanged. Instead I went for the fixer approach that fixes the section after the fact. Setting a keyboard shortcut makes it quicker. The fix is instantaneous by the way, unlike what one is used to when dealing with sections. Having a settings option allows one to set their preferred depth. The tricky part is dealing with the length units input, display and storage. As another peice to this puzzle the following shows how this can be done. The window_closing is the settings save happening when the manger form closes. The pfClip_KeyUp updates the textbox someone is trying to enter the clip setting into so that they can see how Revit will interpret whatever they tried to enter. The setting will be 8 feet If they mess up.

 

 private void Window_Closing(object sender,
            System.ComponentModel.CancelEventArgs e) {
            String pfc = this.pfClip.Text;
            try {
                UnitType clipUnit = UnitType.UT_Length;
                Units thisDocUnits = _doc.GetUnits();
                double userFarClipSetting;
                UnitFormatUtils.TryParse(thisDocUnits,
                    clipUnit, pfc, out userFarClipSetting);
                Properties.Settings.Default.PreferFarClip = userFarClipSetting;

            } catch (Exception) {
                MessageBox.Show("For some unknown reason.\n\nNo change was made.",
                    "Settings Error");
            }
            Properties.Settings.Default.FormFarClip_Top = this.Top;
            Properties.Settings.Default.FormFarClip_Left = this.Left;
            Properties.Settings.Default.FormFarClip_HT = this.Height;
            Properties.Settings.Default.FormFarClip_WD = this.Width;
            Properties.Settings.Default.Save();
        }

        private void pfClip_KeyUp(object sender, KeyEventArgs e) {
            if (e.Key == Key.Return) {
                String pfc = this.pfClip.Text;
                UnitType clipUnit = UnitType.UT_Length;
                Units thisDocUnits = _doc.GetUnits();
                double userFarClipSetting;
                UnitFormatUtils.TryParse(thisDocUnits, clipUnit, pfc,
                    out userFarClipSetting);
                if (userFarClipSetting != 0) {
                    this.pfClip.Text = UnitFormatUtils.Format(thisDocUnits,
                        clipUnit, userFarClipSetting, false, false);
                } else {
                    this.pfClip.Text = "8' - 0\"";
                }
            }
        }

Thanks for the idea mwilson1.

0 Likes
Message 8 of 8

Anonymous
Not applicable

After the far clip gets adjusted, you are most likely to want to see that it has happened or make a final adjustment now that the adjustment control maker is in view. Therefore the command should exit with the section selected. Adding something like the following does that.

 

// make the section selected after this is over.
                List<ElementId> selIds = new List<ElementId>();
                selIds.Add(elem.Id);
                uidoc.Selection.SetElementIds(selIds);
0 Likes