Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Hide elements in linked file

16 REPLIES 16
SOLVED
Reply
Message 1 of 17
Anonymous
6598 Views, 16 Replies

Hide elements in linked file

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

 

16 REPLIES 16
Message 2 of 17
Revitalizer
in reply to: Anonymous

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





Message 3 of 17
Anonymous
in reply to: Revitalizer

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

Message 4 of 17
Revitalizer
in reply to: Anonymous

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





Message 5 of 17
CADdaddy.com
in reply to: Revitalizer

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

 

James

Message 6 of 17

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
Message 7 of 17
sgermanoZ2Y2F
in reply to: Anonymous

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

Message 8 of 17

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;

 

Message 9 of 17
dhanait_ajay13
in reply to: Anonymous

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

Message 10 of 17

Yes, it was added in this latest 2023 version.

 

James

Message 11 of 17

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

Message 12 of 17

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);

 

 

Message 13 of 17
zefreestijl
in reply to: Anonymous

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 :]

 

Message 14 of 17
lvirone
in reply to: Anonymous

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));

 

Message 15 of 17
rmc9WR3X
in reply to: lvirone

@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.

Message 16 of 17
lvirone
in reply to: rmc9WR3X

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));

 

Message 17 of 17
jeremy_tammik
in reply to: lvirone

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report