Hide elements in linked file

Anonymous

Hide elements in linked file

Anonymous
Not applicable

Hi,

 

Manually this is possible in revit. I have main doc and a linked doc. Now I select one element from main doc and one element from linked doc; I do a right click and Hide In View - Elements. Both the selected element gets hidden.

 

Trying to do the same via code:

 

 

FilteredElementCollector links = new FilteredElementCollector(Command.doc).OfCategory(BuiltInCategory.OST_RvtLinks);
            foreach (Document d in Command.app.Documents)
            {

                coll = new FilteredElementCollector(d);
                coll.WherePasses(new LogicalOrFilter(new ElementIsElementTypeFilter(false), new ElementIsElementTypeFilter(true)));
                elemSet = new ElementSet();
                
                foreach (Element el in coll)
                {

                    try
                    {
                        if (el.Id == new ElementId(elementid1) || el.Id == new ElementId(elementid2)
                        {
                           

                            IList<ElementId> ilds = new List<ElementId>();
                            ilds.Add(el.Id);

                            ICollection<ElementId> elemIdsColl = (ICollection<ElementId>)ilds.Cast<ElementId>().ToList();

                          

                            Command.doc.ActiveView.HideElements(ilds);

                        }
                    }
                    catch (Exception sd)
                    {

                        string fg = sd.ToString();
                    }

                }

 

The code hides only the element of the main doc but does not hide the element of the linked doc.

 

 

Thanks & Regards

Sanjay Pandey

 

Reply
Accepted solutions (1)
6,667 Views
16 Replies
Replies (16)

Revitalizer
Advisor
Advisor
Accepted solution

Hi sanjaymann,

 

elements of the linked file are not listed the UI selection since the top level element is still the relating RevitLinkInstance.
There is no relating ElementId you could use with View.Hide method.

So no way to solve your problem.

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Anonymous
Not applicable

Dear Revitalizer,

 

I got your point but I think if revit is able to do the same thing manually. It should be able to it via code too. When you select an element in the linked doc and hide it manually revit might be keeping in mind some sort of name , id, geometry that it has to hide in the linked doc.

 

Thanks & Regards

Sanjay Pandey

0 Likes

Revitalizer
Advisor
Advisor

Hi sanjaymann,

 

no, there are many things that can be done manually but not via code.

For example, the Material creation API: you can define colors and transparency values, but you cannot define textures.

The amount of the available API functions increases every year, but at the moment, there are still many missing ones.

 

In this forum, I see many postings of people who say "but there must be a solution for my problem".

They must accept that some things are not possible to perform, yet.

Of course, sometimes there are workarounds, less or more ugly attempts to bypass problems.

Often they use unsupported functions, so it ist strongly recommended not to use them in productive code.

 

For your problem, I've spent some thoughts about several ways to solve it, but at least, none of the approaches will work properly.

So, there is neither a real solution nor a workaround, from my side.

 

 

Best regards,

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





CADdaddy.com
Collaborator
Collaborator

This thread is a few years old. Does anybody know if this functionality has been added to Revit API yet?

 

James

SONA-ARCHITECTURE
Advocate
Advocate

HI,

 

Does anywhone can confirm that il the Revit API 2018, it's still not possible to hide walls (or an other category) in linked files?

Thx

Pierre NAVARRA
SONA-Architecture.
http://www.sona-architecture.com
https://fr.linkedin.com/in/pierre-navarra-62032a107

sgermanoZ2Y2F
Enthusiast
Enthusiast

Bump - any updates on being able to hide elements in links via api?

0 Likes

james.levieux
Advocate
Advocate

Hi All,

 

Checking in again on this issue with release 2022.  No joy.

 

This is a very important functionality that we need for our interior design firm.  We work on large hotel projects within the architect's linked model.  If we are working on a design option within the architects model, we need to be able to remove certain bits of the architectural work so we can draw our revised layout proposals.  This is extremely painful to do under the current circumstances.  It is crucial to our work to be able to hide and unhide element within linked models.

 

James

 

//get a view in document
FilteredElementCollector collector = new FilteredElementCollector(doc);
collector.OfCategory(BuiltInCategory.OST_Views);
views = collector.ToElements();
View view = (View)views[0];

//get the linked_doc
Element elem = new FilteredElementCollector(doc).OfClass(typeof(RevitLinkInstance)).ToElements()[0];
RevitLinkInstance linked_instance = elem as RevitLinkInstance;
Document linked_doc = linked_instance.GetLinkDocument();

//container to hold element ids
IList<ElementId> IDs = new List<ElementId>();

//Select objects in linked model
IList<Reference> reflist = m_uidoc.Selection.PickObjects(ObjectType.LinkedElement, "Pick elements in linked model");

//get id for each linked element
foreach (Reference rfr in reflist)
{
    Element currentE = linked_doc.GetElement(rfr.LinkedElementId);
    if (currentE.CanBeHidden(view))
    {
        //This line is skipped because the current linked element does not contain a CanBeHidden parameter
        IDs.Add(rfr.LinkedElementId);
    }
    //added this line to collect the IDs even though they haven't been checked for CanBeHidden
    IDs.Add(rfr.LinkedElementId);
}
//Hide doesn't work.  Error msg: "One of the elements cannot be hidden"
view.HideElements(IDs);
return Result.Succeeded;

 

0 Likes

dhanait_ajay13
Enthusiast
Enthusiast

i am also searching for that, Does anybody know if this functionality has been added to Revit API yet?

0 Likes

james.levieux
Advocate
Advocate

Yes, it was added in this latest 2023 version.

 

James

dhanait_ajay13
Enthusiast
Enthusiast

i trying in revit 2023 but still i am not getting any method or solution for this issue

0 Likes

james.levieux
Advocate
Advocate

I may have misled you.  What was added was: Autodesk.Revit.UI.Selection.SetReferences() which allows you to easily add linked elements to a selection set.  It certainly solves the selection difficulties.  I actually haven't yet tried to use this to programmatically hide elements.  Please give that a try and let me know if it works!

 

UIDocument uidoc = commandData.Application.ActiveUIDocument;

IList<Reference> elist =uidoc.Selection.PickObjects(ObjectType.LinkedElement, "Pick elements");

//newly exposed API in Revit 2023:Autodesk.Revit.UI.Selection.SetReferences()
if (elist.Count >0 )uidoc.Selection.SetReferences(refElemLinked);

 

 

0 Likes

zefreestijl
Advocate
Advocate

Hi, I'm currently using API in 2024, 

tried HideCategory, HideElements, IsolateElements and IsolateCategory,

all the functions hide the entire model instead of the element I've given,

 

is there a way to hide linked model by elements / category like how we do in Revit App?

 

Thanks in advance :]

 

0 Likes

lvirone
Enthusiast
Enthusiast

Hello everyone,

 

I've found a solution:

 

//Select elements using UIDocument and then use PostCommand "HideElements"

//elemsFromRevitLinkInstance is "List<Element>", there are the elements you want to hide in the link
var refs = elemsFromRevitLinkInstance.Select(x => new Reference(x).CreateLinkReference(revitLinkInstance)).ToList();

uidoc.Selection.SetReferences(refs);

uidoc.Application.PostCommand(RevitCommandId.LookupPostableCommandId(PostableCommand.HideElements));

 

0 Likes

rmc9WR3X
Enthusiast
Enthusiast

@lvirone Can you provide a description of the process for using your code to hide elements only in a linked model? I am not familiar with the API and deploying a script like this.

0 Likes

lvirone
Enthusiast
Enthusiast

Hello,

 

Here is an sample: Select the first RevitLinkInstance, retrieve the floors, hide the floors

                //Get a link
                var filter = new ElementClassFilter(typeof(RevitLinkInstance));
                var firstInstanceLink = (RevitLinkInstance)new FilteredElementCollector(doc).WherePasses(filter).ToElements().First();

                //Get its floors
                filter = new ElementClassFilter(typeof(Floor));
                var elemsFromRevitLinkInstance = new FilteredElementCollector(firstInstanceLink.GetLinkDocument()).WherePasses(filter).ToElements();

                //Isolate them
                var refs = elemsFromRevitLinkInstance.Select(x => new Reference(x).CreateLinkReference(firstInstanceLink)).ToList();

                uidoc.Selection.SetReferences(refs);
                uidoc.Application.PostCommand(RevitCommandId.LookupPostableCommandId(PostableCommand.HideElements));

 

jeremy_tammik
Autodesk
Autodesk

Thank you Lorenzo, for the good idea and sharing your solution here and in the Revit Idea Station!

 

I added a note in The Building Coder to make your posts more discoverable:

    

https://thebuildingcoder.typepad.com/blog/2024/06/revit-2025-api-video-and-hiding-linked-elements.ht...

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open