Hi Jeremy
This is the detail to reproduce the case:
1- We have a main Revit Model called Assembly16122015-1.rvt. it contains sub-assemblies (external linked files ) and those ones contain other sub-assemblies (external linked files). So we have 3 level external files links.
Our purpose is to read the "links", "documents paths" and "document names" through all external links levels.
2- Behaviour versus expectation: We expected to get links, names and hierarchy of all documents. The problem is that, we can't get the names of the documents linked as attachement to the level2 linked document.
Level0:Assembly16122015-1.rvt.
Level1: Linked document1
Level2: Linked document12
Level3: Linked document121
Level3: Linked document122
Level1:Linked document2
we get the names of document 121 & 122 but we are not able to know that they're the children of document12
3- Revit Sample Models: All files are attached here. Extract all; open the Assembly16122015-1.rvt then load the external links as attachement to the other provided files.
4- Sample Code:
public class SaveCmd : IExternalCommand
{
public struct test
{
public int Level { get; set; }
public Document Doc { get; set; }
}
// The main Execute method (inherited from IExternalCommand) must be public
public Autodesk.Revit.UI.Result Execute(ExternalCommandData revit,
ref string message, ElementSet elements)
{
UIDocument uidoc = revit.Application.ActiveUIDocument;
Document Doc = null;
try
{
Doc = uidoc.Document;
}
catch (SystemException e)
{
TaskDialog.Show("Warning", "No Actif Document");
return Autodesk.Revit.UI.Result.Failed;
}
if (NumberLink(Doc) != 0)
{
List<test> Listtest = new List<test>();
test new_test = new test();
new_test.Level = 0;
new_test.Doc = Doc;
Listtest.Add(new_test);
int i = 0;
int AddLine = 0;
do
{
TaskDialog.Show("Warning", "i=" + i + " Pathname=" + Listtest[i].Doc.PathName);
AddLine = 0;
if (NumberLink(Listtest[i].Doc) != 0)
{
FilteredElementCollector collectorI = new FilteredElementCollector(Listtest[i].Doc);
IList<Element> elemsI = collectorI.OfCategory(BuiltInCategory.OST_RvtLinks).OfClass(typeof(RevitLinkInstance)).ToElements();
foreach (Element eI in elemsI)
{
if (eI is RevitLinkInstance)
{
RevitLinkInstance InstanceType = eI as RevitLinkInstance;
RevitLinkType type = Listtest[i].Doc.GetElement(InstanceType.GetTypeId()) as RevitLinkType;
if (!type.IsNestedLink)
{
new_test = new test();
new_test.Level = Listtest[i].Level + 1;
new_test.Doc = InstanceType.GetLinkDocument();
AddLine++;
TaskDialog.Show("Warning", "Insert index=" + (i + AddLine) + " name=" + InstanceType.GetLinkDocument().PathName);
Listtest.Insert(i + AddLine, new_test);
}
}
}
}
i++;
}
while (i < Listtest.Count);
for (i = 0; i < Listtest.Count; i++)
{
TaskDialog.Show("Debug", "Level = " + Listtest[i].Level + " Pathmane =" + Listtest[i].Doc.PathName);
}
}
return Autodesk.Revit.UI.Result.Succeeded;
}
public static int NumberLink(Document Doc)
{
int nbLink = 0;
FilteredElementCollector links = new FilteredElementCollector(Doc).OfCategory(BuiltInCategory.OST_RvtLinks);
foreach (Element e in links)
{
if (e is RevitLinkType)
{
nbLink++;
}
}
return (nbLink);
}
}
5- Step-By-Step:
- Open the Assembly16122015-1.rvt in Revit
- Reload all links form the provided files. You'll see that it's 3 level linked document
- Select the Assembly16122015-1.rvt and run the code in VB
- The code will continue to show all info captured while reading all links starting from Assembly16122015-1.rvt. When it reaches the Level2 sub-assembly we are not able to see that it has children and what are their names.
Hope this will help understanding the problem.
Thank you for your help