Nested Wall Parts

Hi,

In a new Revit file, I created 6 parts from 2 wall objects with nested parts on purpose to illustrate my question.
I can see 6 different parts in my view, that’s what I want.
image


But in dynamo, if I want to select all my parts in the model, I get 9 items, including the parent parts.

  1. What could be the best way to select only visible parts ?

Then, I’d like to find the orientation of my parts, by getting their parent’s base line (wall).
As long as there are multiple level of child parts, I need to build a recursive code to extract a list containing only wall objects.
Existing node on SteamNodes package will only give first parent, so I get a mix of Wall and Part objects as a result.
image
I tried to construct something as a workaround, but it’s not recursive, so result’s reliability depends on how deep the structure will be.


I find that thread which gives me a little start. But I’m new with the Python for Revit Coding and I can’t find my way out of this.

Code:

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

elements = UnwrapElement(IN[0])
elementlist = list()

def partParent(item):
	if item.Document.GetElement(item.HostElementId) == None:
		elementlist.append(item)
	else:
		partParent(item.Document.GetElement(item.HostElementId))

for elem in elements:
	partParent(elem)

OUT = elementlist
  1. How can I modify that code to recursively extract only very first wall parent ?

Any help would be very much appreciated, thank you in advance.

Would you be able to post the RVT file you are working from?

I think this should do it for you.

On second though this may not work because you can not figure out what wall belongs to what part. I might have time later but for now that is all the time I have.

I’m not currently at my office, so I can’t, but I think it’s pretty simple to reproduce, in 2 minutes max.
The thing will occur whatever wall type or wherever you choose to cut them. And you just need to divide part another time to get nested parts.
I chose to build a new file to be sure that it was not related to a bad construction or a bug in my real project.
In the real file, there are hundreds of parts, just for the first floor.

Hi Steven, thanks for this.
I like this approach, I will try it later. But then, I still need to find the original wall for each part, which is not that simple when you have more walls in the project.

Hi, here is a revit file to reproduce.
Nested Wall Parts #2018.rvt (364 KB)

Ok, I dug a little bit deeper on this, I figured out that parts could also be merged. And in that particular case, there would be several original walls for only one part of the project.

I modified my python code to handle that particular case :

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument

partList = UnwrapElement(IN[0])
parentList = list()

def partParent(item):
	sourceList = item.GetSourceElementIds()
	for source in sourceList:
		sourceElement = doc.GetElement(source.HostElementId)
		if sourceElement.Category.Id == ElementId(-2000269):
			partParent(sourceElement)
		else:
			originList.append(sourceElement)

for part in partList:
	originList = list()
	partParent(part)
	parentList.append(originList)

OUT = parentList


It seems to work…
Any comment ?

This solve my question #2, I still need to figure out a way to filter my parts between last children and intermediate divided parts.

Ok, I like to solve my problems by myself, so here we are.

  1. I made a python node to identify if a part’s parent is a part itself. Then I can compare my input list with the result to filter my parts and keep only the very last children.

  2. I recursively search for the original object that the part comes from, in another python code. It includes cases where the part have been created by merging multiple parts.

I post the files if anyone could be interrested.
File 1.dyn (15.6 KB)
GetPartOriginalParent.dyf (7.2 KB)
IntermediatePartList.dyf (7.2 KB)

2 Likes