Set Wall Compound Layers Function

@Daniel_Aramburu

I still have no idea what your end goal is and why you’d need to do this complicated conversion in the first place. :confused: :slight_smile:

Here’s a script that might possibly do what you need. Use the toggle to convert between finishes to membranes and vice versa :

import clr

clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

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

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

memb = MaterialFunctionAssignment.Membrane
fin1 = MaterialFunctionAssignment.Finish1
fin2 = MaterialFunctionAssignment.Finish2

types = UnwrapElement(IN[0])
f2m = IN[1]

TransactionManager.Instance.EnsureInTransaction(doc)

for t in types:
    cs = t.GetCompoundStructure()
    last_layer = cs.LayerCount - 1
    for i in (0 , last_layer):
        cur_fn = cs.GetLayerFunction(i)
        if f2m and (cur_fn == fin1 or cur_fn == fin2):
            cs.SetLayerFunction(i, memb)
            # membranes require a thickness of 0
            cs.SetLayerWidth(i, 0.0)
        elif not f2m and cur_fn == memb:
            cs.SetLayerFunction(i, fin1)
            # finish layers need some width
            # you'll need to determine those yourself
            cs.SetLayerWidth(i, 0.1)
    t.SetCompoundStructure(cs)

TransactionManager.Instance.TransactionTaskDone()
OUT = 0

This script targets only the first and last layers of the wall because those are commonly the ones defined as finishes.

3 Likes