We are using forge design automation apis in our project. We have a requirement where we need to pass linked file with are main revit file as shown below. We are using revit 2020 as engine.
|-- LinkA.rvt
| |-- LinkA1.rvt
| |-- LinkA2.rvt
|
|-- LinkB.rvt
But when we are getting the linked file using below code in c# revit addin. Then its return an empty array.
List<Element> linkCollector = new FilteredElementCollector(_doc).OfCategory(BuiltInCategory.OST_RvtLinks).WhereElementIsNotElementType().ToList();
Can any one please help me to figure out the solution for this problem?
Are you trying to find RevitLinkInstance or RevitLinkType. The code you have seems to be trying to collect RevitLinkInstance
and if you get an empty list, it is likely due to fact that there are no instances placed for the linked files in the host document.
Do you get an empty array if you drop WhereElementIsNotElementType()
in your filter?
List<Element> linkCollector = new FilteredElementCollector(_doc).OfCategory(BuiltInCategory.OST_RvtLinks).ToList();
To explicitly collect RevitLinkType
you can also do:
List<Element> linkCollector = new FilteredElementCollector(_doc).OfClass(typeof(RevitLinkType)).ToList();
To explicitly collect RevitLinkInstance
you can also do:
List<Element> linkCollector = new FilteredElementCollector(_doc).OfClass(typeof(RevitLinkInstance)).ToList();