view.HideElements() does not work in Revit 2024

view.HideElements() does not work in Revit 2024

natasa.jugovicNDJGN
Explorer Explorer
557 Views
2 Replies
Message 1 of 3

view.HideElements() does not work in Revit 2024

natasa.jugovicNDJGN
Explorer
Explorer

Hi, 

HideElements() method doesn't work in Revit 2024 (and 2023).
I am trying to hide connector in the family.
Hiding elements temporary is not a solution for me, because it will be visible again after closing and opening family again.
I attached a family and here is a code sample.
This was working in 2022.
Any news about this issue?

 

public class Command : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Document document = commandData.Application.ActiveUIDocument.Document;
            View activeView = document.ActiveView;

            FilteredElementCollector collector = new FilteredElementCollector(document, activeView.Id);

            List<ElementId> connectors = collector
                .OfCategory(BuiltInCategory.OST_ConnectorElem)
                .WhereElementIsNotElementType()
                .ToElementIds()
                .ToList();

            Element connector = document.GetElement(connectors[0]);

            using (Transaction transaction = new Transaction(document))
            {
                transaction.Start("Hide Connectors");

                bool canBeHidden = connector.CanBeHidden(activeView);//returns true in 2022, 2023 and 2024 version

                if (connectors.Count > 0)
                    activeView.HideElements(connectors);
      
                transaction.Commit();
            }
            return Result.Succeeded;
        }
    }

 

Regards,

Nataša

 

0 Likes
558 Views
2 Replies
Replies (2)
Message 2 of 3

jeremy_tammik
Alumni
Alumni

So, if I understand correctly, we can narrow down this issue to a bare minimum, can we? Would the following be a valid formulation of the problem you face?

 

  • Connector.CanBeHidden returns true in Revit 2022 and Revit 2023, and false in Revit 2024.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 3

natasa.jugovicNDJGN
Explorer
Explorer

Connector.CanBeHidden returns true for 2024 as well. 
Missed to add it, sorry for that. Edited it now.

0 Likes