Is it possible get all Elements(ids) witch connected to select element?

Is it possible get all Elements(ids) witch connected to select element?

Anonymous
Not applicable
2,913 Views
3 Replies
Message 1 of 4

Is it possible get all Elements(ids) witch connected to select element?

Anonymous
Not applicable

Hello everybody. I am new in programming for Autodesk Revit. I have some task. As example : I have 4 walls witch connected to each other. I want select one of wall, and get Elements Ids all another 3 wall witch connected to it. Can anybody tell me the direction how can i do this, and is it possible?

 

Thank you for advance.

0 Likes
Accepted solutions (1)
2,914 Views
3 Replies
Replies (3)
Message 2 of 4

naveen.kumar.t
Autodesk Support
Autodesk Support
Accepted solution

Hi @Anonymous,

Try the below code

IList<ElementId> joinedElements = new List<ElementId>();
Element selected_wall;

                    Wall w = selected_wall as Wall;
                    GeometryElement geometryElement = w.get_Geometry(new Options());
                    foreach (GeometryObject geometryObject in geometryElement)
                    {
                        if (geometryObject is Solid)
                        {
                            Solid solid = geometryObject as Solid;
                            foreach (Face face in solid.Faces)
                            {
                                // for each face, find the other elements that generated the geometry of that face
                                ICollection<ElementId> generatingElementIds = w.GetGeneratingElementIds(face);

                                generatingElementIds.Remove(w.Id); // remove the originally selected wall, leaving only other elements joined to it
                                foreach (ElementId id in generatingElementIds)
                                {
                                    if (!(joinedElements.Contains(id)))
                                        joinedElements.Add(id); // add each wall joined to this face to the overall collection 
                                }
                            }
                        }
                    }                    
                    uidocument.Selection.SetElementIds(joinedElements);

Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 3 of 4

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @Anonymous,

For administrative purpose,if your question is answered click on "accept solution" button.


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 4 of 4

Anonymous
Not applicable

Thank you, it realy help me. But i have some question. As example. If in wall i make Rectangular Straight Wall Opening (RSWO in future ), and use code to this wall, i see ElementId of RSWO, and other connecting walls. But if i select RSWO and use code to it, i dont see wall Element Id in which RSWO mount. Why this happening? 

 

By the way, i write on pyRevit, and dont use some types as you in CS.

My script now:

__doc__ = "Find all Element that connected to select wall"

__title__ = 'All\nElementIds'

from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Architecture import *
from Autodesk.Revit.DB.Analysis import *

uidoc = __revit__.ActiveUIDocument
doc = __revit__.ActiveUIDocument.Document

def get_selected_elements(doc):
    """API change in Revit 2016 makes old method throw an error"""
    try:
        # Revit 2016
        return [doc.GetElement(id)
                for id in __revit__.ActiveUIDocument.Selection.GetElementIds()]
    except:
        # old method
        return list(__revit__.ActiveUIDocument.Selection.Elements)
selection = get_selected_elements(doc)

for el in selection:
    print el.Id
if len(selection):
    s0 = selection[0]

list = []
option = Options()
geometryElement = s0.get_Geometry(option)
for geometryObject in geometryElement:
    for face in geometryObject.Faces:
        geometryElementIds = s0.GetGeneratingElementIds(face)
        geometryElementIds.Remove(s0.Id)
        for ElementId in geometryElementIds:
		          if list.Contains(ElementId) == False:
			                   list.Add(ElementId)
print list

0 Likes