Get Linked Elements that Appear on Schedule Revit API

Get Linked Elements that Appear on Schedule Revit API

Anonymous
Not applicable
1,365 Views
3 Replies
Message 1 of 4

Get Linked Elements that Appear on Schedule Revit API

Anonymous
Not applicable

Using the Revit API (2017 and above), is there any way to get a list of linked elements that appear on a schedule (including filters, phase filters, etc).

 

Currently, if you query a ViewSchedule using the FilteredElementCollector, it will return N Elements (e.g. Windows, Doors, FamilyInstance) and M RevitLinkInstances. However, the RevitLinkInstance does not list out the actual Element that appears in the linked model. Is there a way to query a RevitLinkInstance in the scope of a ViewSchedule? Or a similar solution?

1,366 Views
3 Replies
Replies (3)
Message 2 of 4

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @Anonymous,

You can get all the elements in Linked Document by using the below code

 RevitLinkInstance RLI;
                    foreach(Document D in app.Documents)
                    {
                        if(D.IsLinked)
                        {
                            FilteredElementCollector FamilyInstances = new FilteredElementCollector(D).OfClass(typeof(FamilyInstance));
                            IList<Element> LinkedElements = FamilyInstances.ToElements() as IList<Element>;
                            foreach(Element element in LinkedElements)
                            {
                                //Do something
                            }
                           
                        }
                    }

For creating ViewSchedule refer the following Link

 

Viewschedule API

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 3 of 4

Anonymous
Not applicable

Thanks for your reply. Unfortunately, the method of provided returns ALL elements from that Linked Instance. What I am looking for is only the linked instances that are contained within the ViewSchedule (e.g. PhaseFilters, ScheduleFilters, DesignOption visibility, etc).

Message 4 of 4

callumf
Contributor
Contributor

Hey Jacob,

I have managed to get it to work by passing the Schedule Id to a new fileteredElementCollector like this:

 

schedule = doc.ActiveView
scheduledElements = list(FilteredElementCollector(doc, schedule.Id))

allElements = []

for element in scheduledElements:
    if element.Category.Name == 'RVT Links':
        linkedElements = list(FilteredElementCollector(element.GetLinkDocument(), schedule.Id))
        for linkedElement in linkedElements:
            allElements.Add(linkedElement)
    else:
        allElements.Add(element)

for element in allElements:
    print element

Let me know if that worked for you aswell