CompoundStructure.SetMaterialId() argument error

Hi all,

Trying to replace the material of a layer within a compound structure but getting one of those annoying errors you can’t work out.

My code:

if cs:
    layers = cs.GetLayers()
    # Iterate through the layers and replace the material
    for i in range(len(layers)):
        if layers[i].MaterialId == find_material.Id:
            TransactionManager.Instance.EnsureInTransaction(doc)
            
            #layers[i].MaterialId = replace_material.Id
            
            cs = CompoundStructure.SetMaterialId(i, replace_material.Id)
            changed = True

This is my error:

This is the API docs page where; as far as I can see, there are only two arguments ?
CompoundStructureLayer Class (revitapidocs.com)

Any idea what argument I’m supposedly missing?

P.S. trying the script on CPython yieds the following error (which also doesn’t make sense because I’m deffo feeding it an element Id)

SetMaterialId is a method of the CompoundStructure class, not a constructor.

So you need to define WHICH compound structure you are working with, not initiate a new one. I think your compound structure is currently CS, so try this: cs.SetMaterialId(i, replace_material.Id).

Ahhh of course, yup that solved it thanks so much.

1 Like