AddObjectsToTree(Autodesk.Revit.DB.BindingMap map, TreeNodeCollection curNodes) { if (map.IsEmpty) { return; // nothing to add } // iterate over the map and add items to the tree Autodesk.Revit.DB.DefinitionBindingMapIterator iter = map.ForwardIterator(); while (iter.MoveNext()) { Definition def = iter.Key; ElementBinding elemBind = (ElementBinding)iter.Current; // TBD: not sure if this map is implemented correctly... doesn't seem to be // find out if this one already exists TreeNode defNode = null; foreach (TreeNode tmpNode in curNodes) { if (tmpNode.Text == def.Name) { defNode = tmpNode; break; } } // this one doesn't exist in the tree yet, add it. if (defNode == null) { defNode = new TreeNode(def.Name); defNode.Tag = iter.Current; curNodes.Add(defNode); } if (elemBind != null) { CategorySet cats = elemBind.Categories; foreach (Category cat in cats) { TreeNode tmpNode = new TreeNode(cat.Name); tmpNode.Tag = cat; defNode.Nodes.Add(tmpNode); } } } }
protected void AddObjectsToTree(Autodesk.Revit.DB.BindingMap map, TreeNodeCollection curNodes) { if (map.IsEmpty) { return; // nothing to add } // iterate over the map and add items to the tree var iter = map.ForwardIterator(); while (iter.MoveNext()) { var def = iter.Key; var elemBind = (ElementBinding)iter.Current; // TBD: not sure if this map is implemented correctly... doesn't seem to be // find out if this one already exists var defNode = curNodes .Cast <TreeNode>() .FirstOrDefault(tmpNode => tmpNode.Text == def.Name); // this one doesn't exist in the tree yet, add it. if (defNode == null) { defNode = new TreeNode(def.Name) { Tag = iter.Current }; curNodes.Add(defNode); } if (elemBind != null) { var cats = elemBind.Categories; foreach (Category cat in cats) { var tmpNode = new TreeNode(cat.Name) { Tag = cat }; defNode.Nodes.Add(tmpNode); } } } }