FamilyType.CompoundStructureLayers does not get all the materials

Hello,

I am a bit stuck here. I have tried to get the material make up of a family type, but both nodes do the one thing that the other can not

The Element.Materials+ nodes from clockwork gives me all the materials of the elements input, but in the wrong order

The FamilyType.CompoundStructureLayers node from Clockwork does not give me all the materials, but so far it seems to give it in the correct order for the materials it can find from the family type

How could I get the material makeup of an element or family type in the correct order as at the moment it doesn’t seem the work?

Has anyone also come across this problem in the past?

I have also uninstalled clock work then reinstalled it again.
I am running Dynamo Revit 2.0.3.8811 and Dynamo Core 2.0.3.8810
Dynamo is running on Revit 2019

Thank you!

Hi @WhoKan_ICan,

I’m not sure if you are still having issues with this, but you can use the python code below which should give you all the materials in the correct order. Just give it the Walls, not the Element Types.

"""
Description: Returns all the Materials used in the walls Compound Layer Structure in order.
Author: Dan Woodcock
Website: https://danimosite.wordpress.com
Licence: N/A
"""

###### Imports ######

import clr

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc =  DocumentManager.Instance.CurrentDBDocument

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

###### Definitions ######

"""
GetLayerMaterials(WallType wt) : Returns Material [ ]
Returns a list of Materials in the same order as the Compund Structure Layers of the given WallType.
"""
def GetLayerMaterials(wt):		
	compStr = wt.GetCompoundStructure()
	if compStr:
		layers = compStr.GetLayers()			
		return [doc.GetElement(l.MaterialId) for l in layers]

"""
tolist(Object obj1) : Returns Object [ ]
Ensure object is a list. If a single non-iterable object given, then it will be wrapped in a list.
"""
def tolist(obj1):
	if hasattr(obj1,"__iter__"): return obj1
	else: return [obj1]

###### Inputs ######

walls = tolist(UnwrapElement(IN[0]))

###### Output ######

outList = []

###### Main Script ######

# Loop through all the given Walls...
for w in walls:
	# Check if the Wall really is a Wall and not some other Element...
	if not w.GetType() == Wall:
		outList.append(None)
		continue
	# Get the Walls WallType (aka FamilyType)	
	wt = w.WallType
	# If the Wall is a Basic Wall (so, not a stacked or curtain etc)...
	if wt.Kind == WallKind.Basic:
		# Get all the Materials in the Walls Compound Structure...
		outList.append(GetLayerMaterials(wt))
		# We have what we need from this wall, skip to next wall...
		continue	
	# If the Wall is a Stacked Wall...
	if wt.Kind == WallKind.Stacked:		
		# Stacked walls are slightly different and require us to get the SubWalls in the stack...
		subWalls = [doc.GetElement(sw) for sw in w.GetStackedWallMemberIds()]
		# Check if there are subwalls...
		if not subWalls == None and len(subWalls) > 0:	
			# Get all the Materials for each subwall (if there is any)...	
			outList.append([GetLayerMaterials(wt.WallType) for wt in subWalls if not wt.WallType.GetCompoundStructure() == None])
		else:
			outList.append(None)		

# Return the results to the Dynamo Workspace...
OUT = outList 

Cheers,
Dan

4 Likes

Hello @Daniel_Woodcock1,

I had some trouble getting into my account hence the delayed reponse

I have tested this as it does what I was after. This is truly amazing and I thank you dearly for your time to help me on this especially that you pretty much covered al the wall types as well :slight_smile:

I have began learning Python and I hope to be able to do the same for floors. Well, I just want to be able to code and utilise the Revit API.

Many thanks,

Hurkan

Good stuff @WhoKan_ICan!

I’m glad this worked for you and it’s great that you are learning Python/Revit API too, a very useful skill to have as you can pretty much do whatever you want (within reason :smile:).

Just before you go, don’t forget to mark as solved! :wink:

Cheers,
Dan