Cannot find attachmentType correctly in link tree.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I rebuild tree link but attachmenttype is incorrect..
My code :
public Autodesk.Revit.UI.Result Execute(ExternalCommandData revit,
ref string message, ElementSet elements)
{
// get active document
Document mainDoc = revit.Application.ActiveUIDocument.Document;
// prepare to show the results...
TreeNode mainNode = new TreeNode();
mainNode.Text = mainDoc.PathName;
// start by the root links (no parent node)
FilteredElementCollector coll = new FilteredElementCollector(mainDoc);
coll.OfClass(typeof(RevitLinkInstance));
foreach (RevitLinkInstance inst in coll)
{
RevitLinkType type = mainDoc.GetElement(inst.GetTypeId()) as RevitLinkType;
if (type.GetParentId() == ElementId.InvalidElementId)
{
TreeNode parentNode = new TreeNode(type.Name+"->"+type.AttachmentType.ToString());
mainNode.Nodes.Add(parentNode);
GetChilds(mainDoc, type.GetChildIds(), parentNode);
}
}
// show the results in a form
System.Windows.Forms.Form resultForm = new System.Windows.Forms.Form();
TreeView treeView = new TreeView();
treeView.Size = resultForm.Size;
treeView.Anchor |= AnchorStyles.Bottom | AnchorStyles.Top;
treeView.Nodes.Add(mainNode);
resultForm.Controls.Add(treeView);
resultForm.ShowDialog();
return Result.Succeeded;
}
private void GetChilds(Document mainDoc, ICollection<ElementId> ids,
TreeNode parentNode)
{
foreach (ElementId id in ids)
{
// get the child information
RevitLinkType type = mainDoc.GetElement(id) as RevitLinkType;
TreeNode subNode = new TreeNode(type.Name + "->" + type.AttachmentType.ToString());
parentNode.Nodes.Add(subNode);
// then go to the next level
GetChilds(mainDoc, type.GetChildIds(), subNode);
}
}
Result :