Hide sections and elevations (lines and bubbles)

Hide sections and elevations (lines and bubbles)

mohamed_ebrahim3016
Contributor Contributor
1,871 Views
14 Replies
Message 1 of 15

Hide sections and elevations (lines and bubbles)

mohamed_ebrahim3016
Contributor
Contributor

I'm making a simple add-in to control the visibility of the multiple sections and elevations that appears in the plan, but I face a problem that I can't identify the section line and bubble (not the view) are in any category in Revit API as I could collect them (I want to catch only the line and bubble). Does anyone know how I could catch it by FilteredElementCollector or PickObject

 

0 Likes
Accepted solutions (1)
1,872 Views
14 Replies
Replies (14)
Message 2 of 15

Moustafa_K
Collaborator
Collaborator

Current it is recorded as a wish to gain access to such elements

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
Message 3 of 15

Mohamed_Arshad
Advisor
Advisor

HI @mohamed_ebrahim3016 

 

    As you mentioned the visibility, Are you trying to Hide/Show of Section Lines ?


Mohamed Arshad K
Software Developer (CAD & BIM)

Message 4 of 15

TripleM-Dev.net
Advisor
Advisor

Hi @mohamed_ebrahim3016,

 

You mean the Section Tag object (line + end symbols)?, Seems to be a "OST_Viewers" builtincategory.

Use RevitLookup to inspect the element.

 

- Michel

Message 5 of 15

admaecc211151
Advocate
Advocate

If you're trying to hide just the bubble( End symbols ), the only way i knew is edit or change the type of section/level directly.

I don't know how to just edit it temply for just a view, either.

Message 6 of 15

mohamed_ebrahim3016
Contributor
Contributor

Yes, by collecting them by (FilteredElementCollector) but I can't get its category to collect them 

0 Likes
Message 7 of 15

mohamed_ebrahim3016
Contributor
Contributor

mohamed_ebrahim3016_0-1714621122938.png

With lookup, I found that the section (line and bubble) always has an Id less than 01 from the section (2D View) Id. So I tried with this approach but I got this exception message (failed to hide section with id xxxxxx: One of the elements cannot be hidden. Parameter name: elementIdSet) Does anyone have an answer

0 Likes
Message 8 of 15

mohamed_ebrahim3016
Contributor
Contributor

Thanks a lot for your help.  Yes, I mean it, but I can't get it specifically from lookup, could you provide me with the approach? also, I got another approach that its Id is always less with 01 from the section itself Id but also I got this exception message (failed to hide section with id 4341411: One of the elements cannot be hidden. Parameter name: elementIdSet). T

0 Likes
Message 9 of 15

Moustafa_K
Collaborator
Collaborator

Section symbols are under category id OST_Viewers.  You can filter using this category

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
0 Likes
Message 10 of 15

TripleM-Dev.net
Advisor
Advisor

Hi @mohamed_ebrahim3016,

 

Turns out "BuiltInCategory.OST_Viewers" would also include the Elevation markers.

Below a sample to hide the section lines in active view:

 

    public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
             
            Document doc = commandData.Application.ActiveUIDocument.Document;

            IEnumerable<Element> SectionLines = new FilteredElementCollector(doc, doc.ActiveView.Id).WhereElementIsNotElementType().OfCategory(BuiltInCategory.OST_Viewers).ToElements();

            List<ElementId> HideElements = new List<ElementId>();
            foreach (Element elem in SectionLines)
            {
                ViewFamilyType VFType = (ViewFamilyType)doc.GetElement(elem.GetTypeId());
                if (VFType.FamilyName == "Section")
                {
                    HideElements.Add(elem.Id);
                }

            }

            if (HideElements.Count > 0)
            {
                using (var t = new Transaction(doc, "Hide Sections in current view"))
                {
                    t.Start();
                    doc.ActiveView.HideElements(HideElements);
                t.Commit();
                }

            }

            return Result.Succeeded;
        }

 

Note that this is a quick sample!, I simply compare the Familyname parameter of the element to get only sectionlines to hide.

 

Also: this element isn't a view, it's a element, and has several parameters pointing to it's "parent" element, however it does not include the Id of it's "Parent (the Section view itself)", so for now I simply compare to the FamilyName "Section", this would fail in other languages!.

 

It does have the name, so the Name + Family/Type could be used to determine which element to hide.

Also it does seem as the Section Line element Id is 1 less than it's Parent view. (This is not documented in the api so could change, do not count on it to stay that way.)

 

- Michel

 

Ps. If you want to toggle the ends of the sectionline, I haven't found any methods in the ViewSection class that could do that (Like with GridLines there's ShowBubbleInView method)

 

 

0 Likes
Message 11 of 15

theknownsilhouette
Enthusiast
Enthusiast

@mohamed_ebrahim3016 
Here's the solution: 

For hiding sections in any views turn off their visibility in the given view. that's how a user does it manually whenever needed. refer below code snippet for the same. Don't forget to accept it as solution if that solves the issue.

Category sectionCategory = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Sections);
                  if (sectionCategory != null)
                    {
                        planView.SetCategoryHidden(sectionCategory.Id, true);
                    }

Learning: First, we need to focus on the manual approach used in Revit for automating any task.

 

 

Though here's what I'm unable to digest:
I tried to achieve the same result using the filtered element collector for several classes or categories and none of them worked. one such sample is below:

List<ElementId> sectionIds = new List<ElementId>();
var sectionCollector = new FilteredElementCollector(doc, planView.Id).OfCategory(BuiltInCategory.OST_Sections).WhereElementIsNotElementType();

                    foreach (var instance in sectionCollector)
                    {
                        sectionIds.Add(instance.Id);
                    }

                    if (sectionIds.Any())
                    {
                        planView.HideElements(sectionIds);
                    }

I expect that "sectionCollector" should return the sections placed in the view, but it returns no elements.

theknownsilhouette_0-1726626853190.png


Maybe The Revit API master @jeremy_tammik can explain us what I'm missing here.

0 Likes
Message 12 of 15

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @mohamed_ebrahim3016 ,

 

Does this help?

 

 FilteredElementCollector collector = new FilteredElementCollector(doc).OfClass(typeof(ViewPlan));
 using (Transaction trans = new Transaction(doc, "Hide ViewSection"))
 {
     trans.Start();
     foreach (ViewPlan v in collector)
     {
         if (v != null && !v.IsTemplate)
         {
             FilteredElementCollector sections = new FilteredElementCollector(doc, v.Id).OfCategory(BuiltInCategory.OST_Viewers);
             IEnumerable<ElementId> elemIds = from Element d in sections where doc.GetElement(d.GetTypeId()).Name.Equals("Building Section") select d.Id;
             ICollection<ElementId> elemIdsColl = (ICollection<ElementId>)elemIds.Cast<ElementId>().ToList();
             if (elemIdsColl.Count > 0)
             {
                 v.HideElements(elemIdsColl);
             }
         }
     }
     trans.Commit();
 }

 


Please refer to the attached screenshot showing the "before" and "after" comparison.
DevBlog Link: https://adndevblog.typepad.com/aec/2013/02/hiding-sections-in-viewplans-using-revit-api.html 

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 13 of 15

mohamed_ebrahim3016
Contributor
Contributor

 

 

0 Likes
Message 14 of 15

TripleM-Dev.net
Advisor
Advisor

Hi @theknownsilhouette,

 

In the first codesample it's  the Category itself. "OST_Sections" = Sections category as seen in ObjectStyles dialog.

 

In the second codesample you are trying to get the element "Section", For some entities this would be identical to the Category and can be retrieved with FilteredElementCollector.OfCategory().

But the actual visible section (line/symbol) is something else, it's a symbolic representation of the actual section view, and in this case it's the OST_Viewers category enum.

But not all "OST_Viewers" are sections (See my earlies reactions)

 

For instance, if you would be doing this with "OST_Walls" it would work for both samples.

 

And I think you wouldn't even get any hits for the whole document using OST_Sections enum.

For views it would be "OST_Views" and then evaluate the View.ViewType for the correct Enum.

Note, using OfClass/OfType usage for ViewSection would also return Elevation views!

 

Views have their own structure, and there are more entities with their own custom structure.

Use https://www.revitapidocs.com/ and read the remaks for classes / methods etc + use RevitLookUp.

0 Likes
Message 15 of 15

mohamed_ebrahim3016
Contributor
Contributor
Accepted solution

As I said that I've realize by "RevitLookUp" that the section as View has usually id with higher by one than the section Element (Line and bubble which appear in the plan view), So after collecting the section views, I iterate over each one get its id and subtract by 1, cast as Element and hide it. 

That what I got and worked good. If anyone need the code I could provide it, or have other approach.

Thank you all...

0 Likes